Part Number Hot Search : 
58LW064 W83321G SA24ARL 1N2441 MAX19 BL2040 PE1145MV PVD1052
Product Description
Full Text Search
 

To Download AT90SCR100LHS-Z1R Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  tpr0327b at90scr100/116/132 technical datasheet (preliminary)
at90scr100/116/132 2 tpr0327b ? vic ? 16fev11
3 tpr0327b ? vic ? 16fev11 at90scr100/116/132 table of contents general features.....................................................................................9 1 block diagram ......................................................................................13 2 pin list configuration .........................................................................15 3 resources .............................................................................................19 4 about code examples .........................................................................21 5 8/16-bit risc cpu core .......................................................................23 5.1 introduction ...................................................................................................23 5.2 architectural overview ..................................................................................23 5.3 alu ? arithmetic logic unit ..........................................................................24 5.4 status register .............................................................................................25 5.5 general purpose register file .....................................................................26 5.6 stack pointer ................................................................................................27 5.7 instruction execution timing ........................................................................27 5.8 reset and interrupt handling ........................................................................28 6 at90scr100/116/132 memories .........................................................31 6.1 in-system reprogrammable flash program memory ..................................31 6.2 sram data memory .....................................................................................32 6.3 eeprom data memory ...............................................................................33 6.4 i/o memory ...................................................................................................39 7 clock system .......................................................................................41 7.1 overview .......................................................................................................41 7.2 clock sources ..............................................................................................43 7.3 clock output buffer ......................................................................................48 7.4 clock system registers ...............................................................................48 8 power management and sleep modes ...............................................51 8.1 power modes descriptions ...........................................................................51 8.2 power reduction register ............................................................................53 8.3 important note about: entering and leaving low consumption modes .........56 8.4 minimizing power consumption ...................................................................56 9 system control and reset ..................................................................59 9.1 resetting the 8/16-bit risc cpu .................................................................59
at90scr100/116/132 4 tpr0327b ? vic ? 16fev11 9.2 reset sources ..............................................................................................59 9.3 internal voltage reference ...........................................................................63 9.4 supply monitor ..............................................................................................63 9.5 watchdog timer ...........................................................................................65 9.6 register description .....................................................................................68 10 interrupts ..............................................................................................71 10.1 interrupt vectors in at90scr100/116/132 ..................................................71 11 external interrupts ...............................................................................77 11.1 external interrupt registers ..........................................................................77 12 i/o ports ................................................................................................83 12.1 standard io ports .........................................................................................83 12.2 specific low speed keyboard output ..........................................................84 12.3 led ...............................................................................................................84 12.4 ports as general digital i/o ..........................................................................85 12.5 register description for i/o-ports .................................................................91 13 timers ...................................................................................................95 13.1 8-bit timer/counter0 with pwm ...................................................................95 13.2 16-bit timer/counter1 with pwm ...............................................................113 13.3 8-bit timer/counter2 with pwm and asynchronous operation (rtc) .......142 13.4 timer/counter prescaler ............................................................................162 14 usb device interface .........................................................................165 14.1 features .....................................................................................................165 14.2 overview .....................................................................................................165 14.3 endpoints description .................................................................................167 14.4 attachment procedure ................................................................................168 14.5 usb interrupts ............................................................................................168 14.6 suspend and resume modes ....................................................................169 14.7 double buffering .........................................................................................171 14.8 usb device registers description .............................................................173 14.9 usbdma controller ....................................................................................181 15 smart card interface block (scib) ...................................................187 15.1 features .....................................................................................................187 15.2 overview .....................................................................................................187 15.3 block diagram ............................................................................................187
5 tpr0327b ? vic ? 16fev11 at90scr100/116/132 15.4 definitions ...................................................................................................188 15.5 functional description ................................................................................190 15.6 additional features .....................................................................................199 15.7 sci registers access ...................................................................................202 15.8 smart card interface block registers ........................................................203 16 dc/dc converter ................................................................................215 16.1 overview .....................................................................................................215 16.2 features .....................................................................................................215 16.3 description ..................................................................................................215 16.4 summary: state machine ...........................................................................216 16.5 dc/dc registers ........................................................................................217 17 usb host controller ..........................................................................219 17.1 features .....................................................................................................219 17.2 usb host smart card interface description ..............................................219 17.3 usb-ic design ...........................................................................................220 17.4 memory management .................................................................................221 17.5 usb host controller description ................................................................222 17.6 interrupt system ..........................................................................................229 17.7 usb host controller registers ...................................................................230 18 usart .................................................................................................245 18.1 features .....................................................................................................245 18.2 usart0 .....................................................................................................245 18.3 overview .....................................................................................................245 18.4 clock generation ........................................................................................246 18.5 frame formats ...........................................................................................249 18.6 usart initialization ....................................................................................250 18.7 data transmission ? the usart transmitter ...........................................252 18.8 data reception ? the usart receiver ....................................................254 18.9 asynchronous data reception ...................................................................258 18.10 multi-processor communication mode .......................................................261 18.11 usart register description ......................................................................263 18.12 examples of baud rate setting ..................................................................268 19 usart in spi mode ...........................................................................271 19.1 features .....................................................................................................271 19.2 overview .....................................................................................................271
at90scr100/116/132 6 tpr0327b ? vic ? 16fev11 19.3 clock generation ........................................................................................271 19.4 spi data modes and timing .......................................................................272 19.5 frame formats ...........................................................................................272 19.6 data transfer ..............................................................................................274 19.7 usart mspim register description .........................................................276 19.8 8/16-bit risc cpu usart mspim vs. 8/16-bit risc cpu spi ................279 20 spi - serial peripheral interface ........................................................281 20.1 features .....................................................................................................281 20.2 description ..................................................................................................281 20.3 ss pin functionality ...................................................................................286 20.4 spi registers ..............................................................................................286 20.5 data modes ................................................................................................289 21 high-speed spi controller ................................................................291 21.1 features .....................................................................................................291 21.2 description ..................................................................................................291 21.3 hsss line functionality ..............................................................................300 21.4 data modes ................................................................................................300 21.5 hsspi interface registers ..........................................................................301 21.6 hsspidma controller ................................................................................306 22 2-wire serial interface _ twi .............................................................311 22.1 features .....................................................................................................311 22.2 twi serial interface bus definition .............................................................311 22.3 data transfer and frame format ...............................................................312 22.4 multi-master bus systems, arbitration and synchronization ......................315 22.5 overview of the twi module ......................................................................316 22.6 using the twi .............................................................................................319 22.7 transmission modes ..................................................................................322 22.8 multi-master systems and arbitration .........................................................337 22.9 twi register description ............................................................................338 23 random number generator ..............................................................343 23.1 features .....................................................................................................343 23.2 rng definition ............................................................................................343 23.3 random number generator registers .......................................................344 24 keyboard interface ............................................................................347 24.1 features .....................................................................................................347
7 tpr0327b ? vic ? 16fev11 at90scr100/116/132 24.2 general description ....................................................................................347 24.3 keyboard register description ...................................................................348 25 aes 128/256 engine ...........................................................................353 25.1 features .....................................................................................................353 25.2 overview .....................................................................................................353 25.3 aes registers description ..........................................................................355 25.4 example. code sample ..............................................................................357 26 jtag interface and on-chip debug system ....................................361 26.1 features .....................................................................................................361 26.2 overview .....................................................................................................361 26.3 tap ? test access port .............................................................................361 26.4 tap controller ............................................................................................363 26.5 using the boundary-scan chain .................................................................364 26.6 using the on-chip debug system ..............................................................364 26.7 on-chip debug specific jtag instructions ................................................365 26.8 on-chip debug related register in i/o memory ........................................366 26.9 using the jtag programming capabilities ................................................366 26.10 bibliography ................................................................................................366 27 ieee 1149.1 (jtag) boundary-scan .................................................367 27.1 features .....................................................................................................367 27.2 system overview ........................................................................................367 27.3 data registers ............................................................................................367 27.4 boundary-scan specific jtag instructions ................................................369 27.5 boundary-scan related register in i/o memory ........................................370 27.6 boundary-scan chain .................................................................................371 27.7 at90scr100/116/132 boundary-scan order ............................................374 27.8 boundary-scan description language files ...............................................376 28 boot loader support - read-while-write self-programming ........377 28.1 boot loader features .................................................................................377 28.2 application and boot loader flash sections ..............................................377 28.3 read-while-write and no read-while-write flash sections .....................378 28.4 boot loader lock bits ................................................................................380 28.5 entering the boot loader program .............................................................381 28.6 addressing the flash during self-programming ........................................383 28.7 self-programming the flash .......................................................................384
at90scr100/116/132 8 tpr0327b ? vic ? 16fev11 29 memory programming .......................................................................391 29.1 program and data memory lock bits ........................................................391 29.2 fuse bits .....................................................................................................393 29.3 signature bytes ..........................................................................................394 29.4 calibration byte ..........................................................................................395 29.5 page size ...................................................................................................395 29.6 serial downloading .....................................................................................395 29.7 serial programming instruction set ............................................................397 29.8 programming via the jtag interface .........................................................399 30 application information .....................................................................413 30.1 ordering information ...................................................................................413 30.2 typical application ......................................................................................414 30.3 pinout .........................................................................................................416 30.4 mechanical information ..............................................................................419 31 electrical characteristics ..................................................................423 31.1 scope .........................................................................................................423 31.2 dc characteristics .....................................................................................423 31.3 ports .......................................................................................................424 31.4 clocks .........................................................................................................424 31.5 communication interfaces ..........................................................................424 31.6 usb interface characteristics ...................................................................428 31.7 smart card interface characteristics .........................................................428 32 register summary .............................................................................431 33 instruction set summary ..................................................................435 reference list .....................................................................................439 revision history..................................................................................439
9 tpr0327b ? vic ? 16fev11 at90scr100/116/132 general features ? high performance, low power 8/16-bit risc cpu microcontroller ? advanced risc architecture ? 132 powerful instructions - most single clock cycle execution ? 32 x 8 general purpose working registers ? up to 16mips throughput at 16mhz ? on-chip 2-cycle multiplier ? non-volatile program and data memories ? 64k/32k/16k bytes of in-system self-programmable flash ? endurance: 10,000 write/erase cycles ? 4k bytes eeprom ? contains 128 bytes of one time programmable memory ? endurance: 100,000 write/erase cycles ? 4k bytes internal sram ? optional boot code section ? in-system programming by on-chip bootloader program ? jtag (ieee std. 1149.1 compliant) interface ? boundary-scan capabilities according to the jtag standard ? extensive on-chip debug support ? programming of flash, eeprom, fuses, and locks bits through jtag interface ? locking jtag for software security (using otp programmation) ? iso7816 uart interface fully compliant with emv, gie-cb and whql standards ? programmable iso clock from 1 mhz to 4.8, 6, 8 or 12mhz ? card insertion/removal detection with automatic deactivation sequence ? programmable baud rate generator from 372 to 3 clock cycles ? synchronous/asynchronous protocols t=0 and t=1 with direct or inverse convention ? automatic character repetition on parity errors ? 32 bit waiting time counter ? 16 bit guard time counter/block guard time counter ? internal step up/down converter with programmable voltage output if dc/dc embedded: ? class a: 5v +/-8% at 60ma, vcc>2.85 (50ma if vcc >2.7) ? class b: 3v +/-8% at 60ma, vcc>2.85 (50ma if vcc >2.7) ? class c: 1.8v +/-8% at 35ma ? iso7816-12 usb host controller for card interface ? supports up to 60ma usb smart cards ? supports limited cable length to smart card connector (~50cm) ? 4 kv esd (mil/std 833 class 3) protection on whole smart card interface ? usb 2.0 full-speed device module ? complies fully with:
at90scr100/116/132 10 tpr0327b ? vic ? 16fev11 ? universal serial bus specification rev 2.0 ? supports data transfer rates up to 12 mbit/s ? endpoint 0 for control transfers : up to 64-bytes ? 8 programmable endpoints with in or out directions and with bulk, interrupt or isochronous transfers ? 3 programmable endpoints with double buffering of 64x2 bytes ? suspend/resume interrupts, and remote wake-up support ? power-on reset and usb bus reset ? 48 mhz clock for full-speed bus operation ? usb bus disconnection on microcontroller request ? peripheral features ? one 8-bit timer/counter with separate prescaler, compare mode and pwm channel ? one 8-bit timer/counter with separate prescaler, compare mode and real time counter on separate oscillator ? one 16-bit timer/counter with separate prescaler and compare mode ? hardware watchdog ? hardware aes 128/256 engine ? random number generator (rng) ? communication peripherals ? high speed master/slave spi serial interface (up to 20mhz) ? 2-wire serial interface ? usart interface (up to 2mbps) ? standard spi interface (to ease the communication with most rf front end chips) ? special microcontroller feature ? power-on reset and brown-out detection ? internal callibrated oscillator ? external and internal interrupt sources ? five sleep modes: idle, power-save, power-down, standby and extended standby ? supply monitoring with interrupt generation below a fixed level. ? keyboard interface with up to 8x8 matrix management capability with interrupts and wake- up on key pressed event ? up to 4 x i/o ports: programmable i/o port ? up to 4 x led outputs with programmable current sources: 2 or 4 ma (not usable in emulation mode) ? specific and unique serial number per ic in production. ? operating temperature ? industrial (-40c to +85c) ? core operating voltages ?2.4 - 5.5v ? dc/dc operating voltages (see ?smart card interface characteristics? for details) ?2.7 - 5.5v
11 tpr0327b ? vic ? 16fev11 at90scr100/116/132 ? maximum frequency ? 8mhz clock input
at90scr100/116/132 12 tpr0327b ? vic ? 16fev11
13 tpr0327b ? vic ? 16fev11 1. block diagram at90scr100/116/132 1. block diagram figure 1-1. note note except for the portc, all the other ports are connected to a pin change interrupt controller. supply monitor vcc xtal1 xtal2 tosc1 tosc2 interrupt controller watchdog on-chip debug keyboard interface 48mhz usb aes 256 rng power management sram 4 kb eeprom 4 kb data flash 64/32/16 kb code 8/16-bit risc cpu spi dma usb dma port a port e port d high-speed spi usart port b spi port c led port twi jtag 8bit t/c 0 16bit t/c 1 8bit t/c 2 timers/counters pwm rtc usb device clock management smart card interface standard iso7816 usb host controller pa7, kbin7, pcint7 pa6, kbin6, pcint6 pa5, kbin5, pcint5 pa4, kbin4, pcint4 pa3, kbin3, pcint3 pa2, kbin2, pcint2 pa1, kbin1, pcint1 pa0, kbin0, pcint0 cpres cclk crst d- cio cc4, dp cc8, dm ucap d+ pe7, kbo7, pcint31 pe6, kbo6, pcint30 pe5, kbo5, pcint29 pe4, kbo4, pcint28 pe3, kbo3, pcint27 pe2, kbo2, pcint26 pe1, kbo1, pcint25 pe0, kbo0, pcint24 pd7, hsmiso, pcint23 pd6, hsmosi, pcint22 pd5, hssck, pcint21 pd4, hsss, pcint20 pd3, int1, pcint19 pd2, int0, oc1b, pcint18 pd1, txd, pcint17 pd0, rxd, pcint16 pb7, sck, oc2a, pcint15 pb6, miso, oc2b, pcint14 pb5, mosi, oc1a, pcint13 pb4, ss, oc0b, pcint12 pb3, pwm, oc0a, pcint11 pb2, icp1, pcint10 pb1, t1, cko, pcint9 pb0, t0, xck, pcint8 pc5, jtgtdi, led3 pc4, jtgtdo, led2 pc3, jtgtms, led1 pc2, jtgtck, led0 pc1, sda, int3b pc0, scl, int2b
at90scr100/116/132 14 tpr0327b ? vic ? 16fev11
15 tpr0327b ? vic ? 16fev11 2. pin list configuration at90scr100/116/132 2. pin list configuration ? 2 package configurations to answer different needs ? 32pins: lowpincount package: for small package size, useful for small embedded systems (at90scr100lhs, at90scr116lhs, at90scr132lhs, at90scr100lsd) ? 64pins: fullpincount: for full performance advanced reader (at90scr100h). caution ! on full pin count (fpc) package, the only supported package type is qfn, and all the vss signals are connected to the e-pad. it is important to have it fully sol- dered on groundplane of final pcb. note note ? usbreg refers to 3.3v usb specific regulator ? pcintx refer to pin change interrupts. see ?external interrupt registers? on page 77. caution ! beware of the multiple functionality supported on each port. all functionnality may not be active at the same time. the only way to disable a feature is to deactive it inside the corresponding peripheral block. table 2-1. pin list configuration portmap id scr100lsd scr1xxlhs (1) scr100h supply configuration, role unmapped, generic pins vcc x x x - vcc voltage supply vss1 x x e (2) vss1 ground avss x x e (2) avss pll ground rst x x x vcc rst reset signal: drive low to reinitialize the chip xtal1 x x x xtal1 clock input: support up to 8 mhz crystals xtal2 x x x xtal2 dvcc x x x dvcc digital vcc :used for internal regulator decoupling vcc2 x x x - vcc2 voltage supply: to be tied to same supply voltage as vcc vcc3 - - x vcc3 voltage supply: to be tied to same supply voltage as vcc vcc4 - - x vcc4 voltage supply: to be tied to same supply voltage as vcc vcc5 - - x vcc5 voltage supply: to be tied to same supply voltage as vcc vdcdcxx x vdcdc voltage supply for dc/dc converter. vss2 x x e (2) vss2 second vss: to be tied to vss vss3 x x e (2) vss3 third vss: to be tied to vss
at90scr100/116/132 16 tpr0327b ? vic ? 16fev11 d+ x x x usb reg d+ usb interface d- x x x d- ucap x x x ucap usb decoupling : used for specific usb regulator decoupling rtc1 - - x vcc tosc1 toscx : 32.768 khz crystals input for real time clock. (please note that these pins are not gpio accessible). rtc2 - - x tosc2 port a pa7 - - x vcc kbin7 pcint7 kbinx : input for ?keyboard interface? pa6 - - x kbin6 pcint6 pa5 - - x kbin5 pcint5 pa4 - - x kbin4 pcint4 pa3 - - x kbin3 pcint3 pa2 - - x kbin2 pcint2 pa1 - - x kbin1 pcint1 pa0 - - x kbin0 pcint0 port b pb7 x - x vcc sck oc2a pcint15 ss, miso, mosi, sck : standard ?spi - serial peripheral interface? ocxx : output comparator outputs. see ?timers? on page 95. icp1 : input capture. see ?16-bit timer/counter1 with pwm? pwm: output from ?8-bit timer/counter0 with pwm? tx : clock input for ?timers? 0 and 1 xck: clock input for synchronous ?usart? intx : ?external interrupts? , default configuration clko : system clock output. (only active if ckout fuse is enabled). ?fuse low byte? . pb6 x - x miso oc2b pcint14 pb5 x - x mosi oc1a pcint13 pb4 x - x ss oc0b pcint12 pb3 - - x pwm oc0a pcint11 pb2 - - x icp1 pcint10 pb1 - - x int3 t1 clko pcint9 pb0 - - x int2 t0 xck pcint8 port c (4) pc5 - - x vcc jtgtdi led3 jtgxxx : ?jtag interface and on-chip debug system? sda, scl : ?2-wire serial interface _ twi? signals ledx : ?led? outputs (io driving current) intxb : ?external interrupts? , bis configuration pc4 - - x jtgtdo led2 pc3 - - x jtgtms led1 pc2 x x x jtgtck led0 pc1 - - x sda int3b pc0 - - x scl int2b table 2-1. pin list configuration portmap id scr100lsd scr1xxlhs (1) scr100h supply configuration, role
17 tpr0327b ? vic ? 16fev11 2. pin list configuration at90scr100/116/132 notes: 1. scr1xxlhs brings at90scr100lhs, at90scr116lhs and at90scr132lhs together. 2. should be connected to e-pad underneath qfn package 3. according to the current configuration, these pins are supplied either by usb regulator or cvcc 4. port c is not complete, due to rtc pins, dedicated to oscillator pads port d pd7 - x x vcc hsmiso pcint23 hsxxxx : ?high-speed spi controller? (miso, mosi, sck, ss) intx : ?external interrupts? , default configuration txd, rxd : ?usart? signals ocxb : output comparators: see ?timers? on page 95. pd6 - x x hsmosi pcint22 pd5 - x x hssck pcint21 pd4 - x x hsss pcint20 pd3 - - x int1 pcint19 pd2 - - x int0 oc1b pcint18 pd1 x x x txd pcint17 pd0 x x x rxd pcint16 port e pe7 - - x vcc kbo7 pcint31 kbox : output for ?keyboard interface? pe6 - - x kbo6 pcint30 pe5 - - x kbo5 pcint29 pe4 - - x kbo4 pcint28 pe3 - - x kbo3 pcint27 pe2 - - x kbo2 pcint26 pe1 - - x kbo1 pcint25 pe0 - - x kbo0 pcint24 smart card port x x x vcc cpres cx : ?smart card interface block (scib)? : standard iso7816 port and ?usb host controller? . xx x cvcc cclk x x x crst xx x cio xx x (3) cc4, dp x x x cc8, dm xx x cvcc cvcc smart card interface: ?dc/dc converter? supply signals x x x cvsense xxe (2) cvss xx x li xx x lo table 2-1. pin list configuration portmap id scr100lsd scr1xxlhs (1) scr100h supply configuration, role
at90scr100/116/132 18 tpr0327b ? vic ? 16fev11
19 tpr0327b ? vic ? 16fev11 3. resources at90scr100/116/132 3. resources a comprehensive set of development tools, appl ication notes and datashe ets are available for download on http://www.insidesecure.com/eng/products/smart-card-readers/contact .
at90scr100/116/132 20 tpr0327b ? vic ? 16fev11
21 tpr0327b ? vic ? 16fev11 4. about code examples at90scr100/116/132 4. about code examples this documentation contains simple code examples that briefly show how to use various parts of the device. be aware that not all c compiler vendors include bit definitions in the header files and interrupt handling in c is compiler dependent. please confirm with the c compiler documen- tation for more details. the code examples assume that the part specific header file is included before compilation. for i/o registers located in extended i/o map, "in", "out", "sbis", "sbic", "cbi", and "sbi" instruc- tions must be replaced with instructions that allow access to extended i/o. typically "lds" and "sts" combined with "sbrs", "sbrc", "sbr", and "cbr".
at90scr100/116/132 22 tpr0327b ? vic ? 16fev11
23 tpr0327b ? vic ? 16fev11 5. 8/16-bit risc cpu core at90scr100/116/132 5. 8/16-bit risc cpu core 5.1 introduction this section discusses the 8/16-bit risc cpu core architecture in general. the main function of the cpu core is to ensure correct program execution. the cpu must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. 5.2 architectural overview figure 5-1. block diagram of the 8/16-bit risc cpu architecture in order to maximize performance and parallelism, the 8/16-bit risc cpu uses a harvard archi- tecture ? with separate memories and buses for program and data. instructions in the program memory are executed with a single level pipelining. while one instruction is being executed, the next instruction is pre-fetched from the program memory. this concept enables instructions to be executed in every clock cycle. the program memory is in-system reprogrammable flash memory. flash program memory instruction register instruction decoder program counter control lines 32 x 8 general purpose registrers alu status and control i/o lines eeprom data bus 8-bit data sram direct addressing indirect addressing interrupt unit spi unit watchdog timer i/o module 2 i/o module1 i/o module n
at90scr100/116/132 24 tpr0327b ? vic ? 16fev11 the fast-access register file contains 32 x 8-bit general purpose working registers with a single clock cycle access time. this allows single-cycle arithmetic logic unit (alu) operation. in a typ- ical alu operation, two operands are output from the register file, the operation is executed, and the result is stored back in the register file ? in one clock cycle. six of the 32 registers can be used as three 16-bit indirect address register pointers for data space addressing ? enabling efficient address calculations. one of the these address pointers can also be used as an address pointer for look up tables in flash program memory. these added function registers are the 16-bit x-, y-, and z-register, described later in this section. the alu supports arithmetic and logic operations between registers or between a constant and a register. single register operations can also be executed in the alu. after an arithmetic opera- tion, the status register is updated to reflect information about the result of the operation. program flow is provided by conditional and unconditional jump and call instructions, able to directly address the whole address space. most 8/16-bit risc cpu instructions have a single 16-bit word format. every program memory address contains a 16- or 32-bit instruction. program flash memory space is divided in two sections, the boot program section and the application program section. both sections have dedicated lock bits for write and read/write protection. the spm instruction that writes into the flash memory must reside in the boot pro- gram section. during interrupts and subroutine calls, the return address program counter (pc) is stored on the stack. the stack is effectively allocated in the general data sram, and consequently the stack size is only limited by the total sram size and the usage of the sram. all user programs must initialize the sp in the reset routine (before subroutines or interrupts are executed). the stack pointer (sp) is read/write accessible in the i/o space. the data sram can easily be accessed through the five different addressing modes supported in the 8/16-bit risc cpu architecture. the memory spaces in the 8/16-bit risc cpu architecture are all linear and regular memory maps. a flexible interrupt module has its control registers in the i/o space with an additional global interrupt enable bit in the status register. all interrupts have a separate interrupt vector in the interrupt vector table. the interrupts have priority in accordance with their interrupt vector posi- tion. the lower the interrupt vector address, the higher the priority. the i/o memory space contains 64 addresses for cpu peripheral functions as control regis- ters, spi, and other i/o functions. the i/o memory can be accessed directly, or via the data space locations following those of the regi ster file, 0x20 - 0x5f. in addition, the at90scr100/116/132 has extended i/o space from 0x60 - 0xff in sram where only the st/sts/std and ld/lds/ldd instructions can be used. 5.3 alu ? arithmetic logic unit the high-performance 8/16-bit risc cpu alu operates in direct connection with all the 32 gen- eral purpose working registers. within a singl e clock cycle, arithmetic operations between general purpose registers or between a register and an immediate operand are executed. the alu operations are divided into three main categories ? arithmetic, logical, and bit-functions. this implementation of the architecture also provides a powerful multiplier supporting both signed/unsigned multiplication and fractional format. see the ?instruction set? section for a detailed description.
25 tpr0327b ? vic ? 16fev11 5. 8/16-bit risc cpu core at90scr100/116/132 5.4 status register the status register contains information about the result of the most recently executed arithme- tic instruction. this information can be used for altering program flow in order to perform conditional operations. note that the status register is updated after all alu operations, as specified in the instruction set reference. this will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. the status register is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. this must be handled by software. 5.4.1 sreg ? status register the 8/16-bit risc cpu status register ? sreg ? is defined as: ? bit 7 ? i: global interrupt enable the global interrupt enable bit must be set for the interrupts to be enabled. the individual inter- rupt enable control is then performed in separate control registers. if the global interrupt enable register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. the i-bit is cleared by hardware after an interrupt has occurred, and is set by the reti instruction to enable subsequent interrupts. the i-bit can also be set and cleared by the application with the sei and cli instructions, as described in the instruction set reference. ? bit 6 ? t: bit copy storage the bit copy instructions bld (bit load) and bst (bit store) use the t-bit as source or desti- nation 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. half carry is useful in bcd arithmetic. see ?instruction set summary? on page 435 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 ?instruction set summary? on page 435 for detailed information. ? bit 3 ? v: two?s complement overflow flag the two?s complement overflow flag v supports two?s complement arithmetic. see ?instruction set summary? on page 435 for detailed information. ? bit 2 ? n: negative flag the negative flag n indicates a negative result in an arithmetic or logic operation. see ?instruc- tion set summary? on page 435 for detailed information. ? bit 1 ? z: zero flag bit 76543 2 10 0x3f (0x5f) i t h s v n z c sreg read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 26 tpr0327b ? vic ? 16fev11 the zero flag z indicates a zero result in an arithmetic or logic operation. see ?instruction set summary? on page 435 for detailed information. ? bit 0 ? c: carry flag the carry flag c indicates a carry in an arithmetic or logic operation. see ?instruction set sum- mary? on page 435 for detailed information. 5.5 general purpose register file the register file is optimized for the 8/16-bit enhanced risc instruction set. in order to achieve the required performance and flexibility, the following input/output schemes are supported by the register file: ? one 8-bit output operand and one 8-bit result input ? two 8-bit output operands and one 8-bit result input ? two 8-bit output operands and one 16-bit result input ? one 16-bit output operand and one 16-bit result input figure 5-2 shows the structure of the 32 general purpose working registers in the cpu. figure 5-2. 8/16-bit risc cpu general purpose working registers most of the instructions operating on the register file have direct access to all registers, and most of them are single cycle instructions. as shown in figure 5-2 , each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user data space. although not being physically imple- mented as sram locations, this memory organization provides great flexibility in access of the registers, as the x-, y- and z-pointer registers can be set to index any register in the file. 5.5.1 the x-register, y-register, and z-register the registers r26..r31 can also be used as 16- bit address pointers for indirect addressing of the data space. the three indirect address registers x, y, and z are defined as described in fig- ure 5-3 . 70addr. r0 0x00 r1 0x01 r2 0x02 ? r13 0x0d general r14 0x0e purpose r15 0x0f working r16 0x10 registers r17 0x11 ? r26 0x1a x-register low byte r27 0x1b x-register high byte r28 0x1c y-register low byte r29 0x1d y-register high byte r30 0x1e z-register low byte r31 0x1f z-register high byte
27 tpr0327b ? vic ? 16fev11 5. 8/16-bit risc cpu core at90scr100/116/132 figure 5-3. the x-, y-, and z-registers in the different addressing modes these address registers have fixed displacement, automatic increment, and automatic decrement functionality (see the instruction set reference for details). 5.6 stack pointer the stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. the stack pointer register always points to the top of the stack. note that the stack is implemented as growing from higher memory loca- tions to lower memory locations. this implies that a stack push command decreases the stack pointer. the stack pointer points to the data sram stack area where the subroutine and interrupt stacks are located. this stack space in the data sram must be defined by the program before any subroutine calls are executed or interrupts are enabled. the stack pointer must be set to point above 0x0100. the initial value of the sta ck pointer is the highest address of the internal sram. the stack pointer is decremented by one when data is pushed onto the stack with the push instruction, and it is decremented by two when the return address is pushed onto the stack with subroutine call or interrupt. the stack pointer is incremented by one when data is popped from the stack with the pop instruction, and it is incremented by two when data is popped from the stack with return from subroutine ret or return from interrupt reti. the 8/16-bit risc cpu stack pointer is implemented as two 8-bit registers in the i/o space. the number of bits actually used is implementation dependent. 5.7 instruction execution timing this section describes the general access timing concepts for instruction execution. the 8/16-bit risc cpu is driven by the cpu clock clk cpu , directly generated from the selected clock source for the chip. no internal clock division is used. 15 xh xl 0 x-register 7 0 7 0 r27 (0x1b) r26 (0x1a) 15 yh yl 0 y-register 7 0 7 0 r29 (0x1d) r28 (0x1c) 15 zh zl 0 z-register 7 0 7 0 r31 (0x1f) r30 (0x1e) bit 1514131211 10 9 8 0x3e (0x5e) - - - sp12 sp11 sp10 sp9 sp8 sph 0x3d (0x5d) sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 spl 76543 2 10 read/write r r r 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 1 0 0 0 0 0x10 11111 1 110xff
at90scr100/116/132 28 tpr0327b ? vic ? 16fev11 figure 5-4 shows the parallel instruction fetches and instruction executions enabled by the har- vard architecture and the fast-access register file concept. this is the basic pipelining concept to obtain up to 1 mips per mhz with the corresponding unique results for functions per cost, functions per clocks, and functions per power-unit. figure 5-4. the parallel instruction fetches and instruction executions figure 5-5 shows the internal timing concept for the register file. in a single clock cycle an alu operation using two register operands is executed, and the result is stored back to the destina- tion register. figure 5-5. single cycle alu operation 5.8 reset and interrupt handling the 8/16-bit risc cpu provides several different interrupt sources. these interrupts and the separate reset vector each have a separate program vector in the program memory space. all interrupts are assigned individual enable bits which must be written logic one together with the global interrupt enable bit in the status register in order to enable the interrupt. depending on the program counter value, interrupts may be automatically disabled when boot lock bits blb02 or blb12 are programmed. this feature improves software security. see the section ?memory programming? on page 391 for details. the lowest addresses in the program memory space are by default defined as the reset and interrupt vectors. the complete list of vectors is shown in ?interrupts? on page 71 . the list also determines the priority levels of the different interrupts. the lower the address the higher is the priority level. reset has the highest priority, and next is int0 ? the external interrupt request 0. the interrupt vectors can be moved to the start of the boot flash section by setting the ivsel bit in the mcu control register (mcucr). refer to ?interrupts? on page 71 for more information. the reset vector can also be moved to the start of the boot flash section by programming the bootrst fuse, see ?memory programming? on page 391 . clk 1st instruction fetch 1st instruction execute 2nd instruction fetch 2nd instruction execute 3rd instruction fetch 3rd instruction execute 4th instruction fetch t1 t2 t3 t4 cpu ime register operands fetch alu operation execute rite back t1 t2 t3 t4 clk cpu total execution t result w
29 tpr0327b ? vic ? 16fev11 5. 8/16-bit risc cpu core at90scr100/116/132 when an interrupt occurs, the global interrupt enable i-bit is cleared and all interrupts are dis- abled. the user software can write logic one to the i-bit to enable nested interrupts. all enabled interrupts can then interrupt the current interrupt routine. the i-bit is automatically set when a return from interrupt instruction ? reti ? is executed. there are basically two types of interrupts. the fi rst type is triggered by an event that sets the interrupt flag. for these interrupts, the program counter is vectored to the actual interrupt vec- tor in order to execute the interrupt handling routine, and hardware clears the corresponding interrupt flag. interrupt flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. if an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the interrupt flag will be set and remembered until the interrupt is enabled, or the flag is cleared by software. similarly, if one or more interrupt conditions occur while the global interrupt enable bit is cleared, the corresponding interr upt flag(s) will be set and remembered until the global interrupt enable bit is set, and will then be executed by order of priority. the second type of interrupts will trigger as long as the interrupt condition is present. these interrupts do not necessarily have interrupt flags. if the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. when the 8/16-bit risc cpu exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. note that the status register is not automatically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. this must be handled by software. when using the cli instruction to disable interrupts, the interrupts will be immediately disabled. no interrupt will be executed after the cli instruction, even if it occurs simultaneously with the cli instruction. the following example shows how this can be used to avoid interrupts during the timed eeprom write sequence. when using the sei instruction to enable interrupts, the instruction following sei will be exe- cuted before any pending interrupts, as shown in this example. assembly code example in r16, sreg ; store sreg value cli ; disable interrupts during timed sequence sbi eecr, eempe ; start eeprom write sbi eecr, eepe out sreg, r16 ; restore sreg value (i-bit) c code example char csreg; csreg = sreg; /* store sreg value */ /* disable interrupts during timed sequence */ __disable_interrupt(); eecr |= (1< at90scr100/116/132 30 tpr0327b ? vic ? 16fev11 5.8.1 interrupt response time the interrupt execution response for all the enabled 8/16-bit risc cpu interrupts is five clock cycles minimum. after five clock cycles the program vector address for the actual interrupt han- dling routine is executed. during these five clock cycle periods, the program counter is pushed onto the stack. the vector is normally a jump to the interrupt routine, and this jump takes three clock cycles. if an interrupt occurs during execution of a multi-cycle instruction, this instruction is completed before the interrupt is served. if an interrupt occurs when the mcu is in sleep mode, the interrupt execution response time is increased by five clock cycles. this increase comes in addition to the start-up time from the selected sleep mode. a return from an interrupt handling routine takes five clock cycles. during these five clock cycles, the program counter (three bytes) is popped back from the stack, the stack pointer is incre- mented by three, and the i-bit in sreg is set. assembly code example sei ; set global interrupt enable sleep ; enter sleep, waiting for interrupt ; note: will enter sleep before any pending ; interrupt(s) c code example __enable_interrupt(); /* set global interrupt enable */ __sleep(); /* enter sleep, waiting for interrupt */ /* note: will enter sleep before any pending interrupt(s) */
31 tpr0327b ? vic ? 16fev11 6. at90scr100/116/132 memories at90scr100/116/132 6. at90scr100/116/132 memories this section describes the different memories in the at90scr100, at90scr116 and at90scr132. the 8/16-bit risc cpu architectu re has two main memory spaces: the data memory and the program memory spaces. in addition, the at90scr100/116/132 feature an eeprom memory for data storage. all three memory spaces are linear and regular. 6.1 in-system reprogrammable flash program memory the at90scr100/116/132 contain respectively 64k/16k/3k2 bytes on-chip in-system repro- grammable flash memory for program storage. as all 8/16-bit risc cpu instructions are 16 or 32 bits wide, the flash is organized as 32k/8k/16k x 16. for software security, the flash pro- gram memory space is divided into two sections, boot program section and application program section. see ?application and boot loader flash sections? on page 377. the flash memory has an endurance of at least 10,000 write/erase cycles. the at90scr100/116/132 program counter (pc) is 15/16 bits wide, which permits to address the 64k/16k/32k program memory locations. the operation of boot program section and associ- ated boot lock bits for software protection are described in detail in ?memory programming? on page 391 . ?memory programming? on page 391 contains a detailed description of flash data serial downloading using the spi pins or the jtag interface. constant tables can be allocated within the entire program memory address space (see the lpm ? load program memory instruction description). timing diagrams for instruction fetch and execution are presented in ?instruction execution tim- ing? on page 27 .
at90scr100/116/132 32 tpr0327b ? vic ? 16fev11 figure 6-1. full memory map 6.2 sram data memory figure 6-1 shows how the sram memory is organized. the at90scr100/116/132 are complex microcontrollers with more peripheral units than can be supported within the 64 locations reserved in the opcode of the in and out instructions. for the extended i/o space from 0x0060 - 0x00ff in sram, only the st/sts/std and ld/lds/ldd instructions can be used. the address range $00 - $10ff data memory address the register file, the i/o memory, extended i/o memory, and the internal data sram. the first 32 locations address the register file, the next 64 location the standard i/o memory, then 160 locations of extended i/o memory and the next 4,096 locations address the internal data sram. the five different addressing modes for the data memory cover: direct, indirect with displace- ment, indirect, indirect with pre-decrement, and indirect with post-increment. in the register file, registers r26 to r31 feature the indirect addressing pointer registers. the direct addressing reaches the entire data space. the indirect with displacement mode reaches 63 address locations from the base address given by the y- or z-register. when using register indirect addressing modes with automatic pre-decrement and post-incre- ment, the address registers x, y, and z are decremented or incremented. application flash section 16 bits 0x0000 0x001f 0x0020 0x005f 0x0060 0x00ff 0x0100 0x10ff 0x1000 0x0000 0x0000 0x0fff 0x1000 0x1fff scr116 0x0000 0x6fff 0x7000 0x7fff scr100 boot flash section program memory sram memory io registers 32 general purpose working registers peripheral registers eeprom data memory eeprom memory data memory 0x0000 0x2fff 0x3000 0x3fff scr132 8 bits
33 tpr0327b ? vic ? 16fev11 6. at90scr100/116/132 memories at90scr100/116/132 the 32 general purpose working registers, 64 i/o registers, 160 extended i/o registers and the 4096 bytes of internal data sram are all acce ssible through all these addressing modes. the register file is described in ?general purpose register file? on page 26 . 6.2.1 data memory access times this section describes the general access timi ng concepts for internal memory access. the internal data sram access is performed in two clk cpu cycles as described in figure 6-2 . figure 6-2. on-chip data sram access cycles 6.3 eeprom data memory the at90scr100/116/132 contain 4k bytes of data eeprom memory. it is organized as a separate data space, in which single bytes can be read and written. the eeprom has an endurance of at least 100,000 write/erase cycles. the access between the eeprom and the cpu is described in the following section, specifying the eeprom address registers, the eeprom data register, and the eeprom control register. for a detailed description of spi and jtag downloading to the eeprom, see page 395 , and page 399 respectively. 6.3.1 eeprom read/write access the eeprom access registers are accessible in the i/o space. the write access time is a self-timing function, wich allows the user software to detect when the next byte can be written. if the user code contains instructions that write the eeprom, some precautions must be taken. in heavily filtered power supplies, v cc is likely to rise or fall slowly on power-up/down. this causes the device, for some period of time, to run at a voltage lower than specified as minimum, for the clock frequency used. for details on how to avoid problems in these situations, see ?preventing eeprom corruption? on page 38. in order to prevent unintentional eeprom writes , a specific write procedure must be followed. refer to the description of the eeprom control register for details on this. clk wr rd data data address address valid t1 t2 t3 compute address read write cpu memory access instruction next instruction
at90scr100/116/132 34 tpr0327b ? vic ? 16fev11 when the eeprom is read, the cpu is halted for four clock cycles before the next instruction is executed. when the eeprom is written, the cpu is halted for two clock cycles before the next instruction is executed. 6.3.2 eearh and eearl ? the eeprom address register ? bits 15..12 ? res : reserved bits these bits are reserved bits and will always read as zero. ? bits 11..0 ? eear8..0 : eeprom address the eeprom address registers ? eearh and eearl specify the eeprom address in the 4k bytes eeprom space. the eeprom data byte s are addressed linear ly between 0 and 4096. the initial value of eear is undefined. a proper value must be written before the eeprom may be accessed. 6.3.3 eedr ? the eeprom data register ? bits 7..0 ? eedr7..0 : eeprom data for the eeprom write operation, the eedr register contains the data to be written to the eeprom in the address specified by the eear register. for the eeprom read operation, the eedr contains the data read out from the eeprom at the address specified by eear. 6.3.4 eecr ? the eeprom control register ? bits 7..6 ? res: reserved bits these bits are reserved bit and will always read as zero. ? bits 5..4 ? eepm1..0 : eeprom programming mode bits the eeprom programming mode bit setting defin es which programming action will be trig- gered when writing eepe. it is possible to program data in one atomic operation (erase the old bit 1514131211 10 9 8 0x22 (0x42) ---- eear [11..8] eearh 0x21 (0x41) eear [7..0] eearl bit 76543210 read/writerrrrr/wr/wr/wr/w r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 x x x x xxxxx x xx bit 76543 2 10 0x20 (0x40) eedr [7..0] eedr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 0x1f (0x3f) - - eepm1 eepm0 eerie eempe eepe eere eecr read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 x x 0 0 x 0
35 tpr0327b ? vic ? 16fev11 6. at90scr100/116/132 memories at90scr100/116/132 value and program the new value) or to split the erase and write operations in two different operations. the programming times for the different modes are shown in table 6-1 . while eepe is set, any write to eepmn will be ignored. during reset, the eepmn bits will be reset to 00 unless the eeprom is busy programming. ? bit 3 ? eerie: eeprom ready interrupt enable writing eerie to one enables the eeprom ready interrupt if the i bit in sreg is set. writing eerie to zero disables the interrupt. the eeprom ready interrupt generates a constant inter- rupt when eepe is cleared. ? bit 2 ? eempe: eeprom master programming enable the eempe bit determines whether setting eepe to one causes the eeprom to be written or not. if eempe is set, setting eepe within four clock cycles will write data to the eeprom at the selected address. if eempe is clear, setting eepe will have no effect. when eempe has been written to one by software, hardware clears the bit to zero after four clock cycles. see the description of the eepe bit for the eeprom write procedure. ? bit 1 ? eepe: eeprom programming enable the eeprom write enable signal eepe is the write strobe to the eeprom. when address and data are correctly set up, the eepe bit must be written to one to write the value into the eeprom. the eempe bit must be written to one before a logical one is written to eepe, other- wise no eeprom write takes place. the following procedure should be followed when writing the eeprom (the order of steps 3 and 4 is not essential): 1. wait until eepe becomes zero. 2. wait until spmen in spmcsr becomes zero. 3. write new eeprom address to eear (optional). 4. write new eeprom data to eedr (optional). 5. write a logical one to the eempe bit while writing a zero to eepe in eecr. 6. within four clock cycles after setting eempe, write a logical one to eepe. the eeprom can not be programmed during a cpu write to the flash memory. the software must check that the flash programming is completed before initiating a new eeprom write. this is performed by step 2. step 2 is only relevant if the software contains a boot loader allow- table 6-1. eeprom mode bits eepm1 eepm0 programming time operation 0 0 3.4 ms erase and write in one operation (atomic operation) 0 1 1.8 ms erase only 1 0 1.8 ms write only 1 1 ? reserved for future use
at90scr100/116/132 36 tpr0327b ? vic ? 16fev11 ing the cpu to program the flash. if the flash is never being updated by the cpu, step 2 can be omitted. see ?memory programming? on page 391 for details about boot programming. when the write access time has elapsed, the eepe bit is cleared by hardware. the user soft- ware can poll this bit and wait for a zero before writing the next byte. when eepe has been set, the cpu is halted for two cycles before the next instruction is executed. ? bit 0 ? eere: eeprom read enable the eeprom read enable signal eere is the read strobe to the eeprom. when the correct address is set up in the eear register, the eere bit must be written to a logic one to trigger the eeprom read. the eeprom read access takes one instruction, and the requested data is available immediately. when the eeprom is read, the cpu is halted for four cycles before the next instruction is executed. the user should poll the eepe bit before starting the read operation. if a write operation is in progress, it is neither possible to read the eeprom, nor to change the eear register. caution ! an interrupt between step 5 and step 6 will make the write cycle fail, since the eeprom master write enable will time-out. if an interrupt routine accessing the eeprom is interrupting another eeprom access, the eear or eedr register will be modified, causing the interrupted eeprom access to fail. it is recom- mended that the global interrupt flag is cleared during all the steps to avoid these problems.
37 tpr0327b ? vic ? 16fev11 6. at90scr100/116/132 memories at90scr100/116/132 6.3.5 code examples for eeprom manipulation the following code examples show one assembly and one c function for writing to the eeprom. the examples assume that interrupts are controlled (e.g. by disabling interrupts glob- ally) so that no interrupts will occur during ex ecution of these functi ons. the examples also assume that no flash boot loader is present in the software. if such code is present, the eeprom write function must also wait for any ongoing spm command to finish. assembly code example eeprom_write: ; wait for completion of previous write sbic eecr,eepe rjmp eeprom_write ; set up address (r18:r17) in address register out eearh, r18 out eearl, r17 ; write data (r16) to data register out eedr,r16 ; write logical one to eempe sbi eecr,eempe ; start eeprom write by setting eepe sbi eecr,eepe ret c code example void eeprom_write( unsigned int uiaddress, unsigned char ucdata) { /* wait for completion of previous write */ while(eecr & (1< at90scr100/116/132 38 tpr0327b ? vic ? 16fev11 the next code examples show assembly and c functions for reading the eeprom. the exam- ples assume that interrupts are controlled so that no interrupts will occur during execution of these functions. 6.3.6 preventing eeprom corruption during periods of low v cc, the eeprom data can be corrupted because the supply voltage is too low for the cpu and the eeprom to operate properly. these issues are the same as for board level systems using eeprom, and the same design solutions should be applied. an eeprom data corruption can be caused by two situations when the voltage is too low. 1. a regular write sequence to the eeprom requires a minimum voltage to operate correctly. 2. the cpu itself can execute instructions incorrectly, if the supply voltage is too low. eeprom data corruption can easily be avoided by following this design recommendation: keep the 8/16-bit risc cpu reset active (low) during periods of insufficient power supply voltage. this can be done by enabling the internal brown-out detector (bod). if the detec- tion level of the internal bod does not match the needed detection level, an external low v cc reset protection circuit can be used. if a reset occurs while a write operation is in prog- ress, the write operation will be completed assuming that the power supply voltage is sufficient. assembly code example eeprom_read: ; wait for completion of previous write sbic eecr,eepe rjmp eeprom_read ; set up address (r18:r17) in address register out eearh, r18 out eearl, r17 ; start eeprom read by writing eere sbi eecr,eere ; read data from data register in r16,eedr ret c code example unsigned char eeprom_read( unsigned int uiaddress) { /* wait for completion of previous write */ while(eecr & (1< 39 tpr0327b ? vic ? 16fev11 6. at90scr100/116/132 memories at90scr100/116/132 6.4 i/o memory the i/o space definition of the at90scr100/116/132 is shown in ?register summary? on page 431 . all at90scr100/116/132 i/os and peripherals are placed in the i/o space. all i/o locations may be accessed by the ld/lds/ldd and st/sts/std instructions, transferring data between the 32 general purpose working registers and the i/o space. i/o registers within the address range 0x00 - 0x1f are directly bit-accessible using the sbi and cbi instructions. in these registers, the value of single bits can be checked by using the sbis and sbic instructions. refer to the instruction set section for more details. when using the i/o specific commands in and out, i/o addresses 0x00 - 0x3f must be used. when addressing i/o registers as data space using ld and st instructions, 0x20 must be added to these addresses. the at90scr100/116/132 are complex microcontrollers with more peripheral units than can be supported within the 64 location reserved in the opcode of the in and out instructions. for the extended i/o space from 0x60 - 0xff in sram, only the st/sts/std and ld/lds/ldd instructions can be used. for compatibility with future devices, reserved bits should be written to zero if accessed. reserved i/o memory addresses should never be written. some of the status flags are cleared by writing a logical one to them. note that, unlike most other 8/16-bit risc cpus, the cbi and sbi instructions will only operate on the specified bit, and can therefore be used on registers containing such status flags. the cbi and sbi instruc- tions work with registers 0x00 to 0x1f only. the i/o and peripherals control registers are explained in later sections. 6.4.1 general purpose i/o registers the at90scr100/116/132 contain three general pu rpose i/o registers. these registers can be used for storing any information, and they are particularly useful for storing global variables and status flags. general purpos e i/o registers within the address range 0x00 - 0x1f are directly bit-accessible using the sbi, cbi, sbis, and sbic instructions. 6.4.2 gpior2 ? general purpose i/o register 2 6.4.3 gpior1 ? general purpose i/o register 1 bit 76543 2 10 0x2b (0x4b) gpior2 [7..0] gpior2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 0x2a (0x4a) gpior1 [7..0] gpior1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 40 tpr0327b ? vic ? 16fev11 6.4.4 gpior0 ? general purpose i/o register 0 bit 76543 2 10 0x1e (0x3e) gpior0 [7..0] gpior0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
41 tpr0327b ? vic ? 16fev11 7. clock system at90scr100/116/132 7. clock system 7.1 overview the clock system of at90scr100/116/132 is based on a 8mhz oscillator which feeds a phase lock loop (pll) providing a 96mhz clock frequency. then, dividers permit to calibrate the fre- quencies available for the different peripherals, core and memories. all of the clocks do not need to be active at a given time. in order to reduce power consumption, the clocks to modules not being used can be stopped by using different sleep modes, as described in ?power management and sleep modes? on page 51 . the clock systems are detailed below. figure 7-1 presents the principal clock systems in the at90scr100/116/132 and their distribution. figure 7-1. clock distribution core divider internal rc oscillator hs spi divider xtal1 xtal2 clk xtal clk xtal clk pll clk mux xtal glitches free (default) (default) (default) (default) 96mhz 48mhz (by 1, 4, 5, 6, 8, 12, 24, 48, 96) (by 4, 5, 6, 8, 12, 24, 48, 96) (divider by 1 only for clk ) clk cpu clk flash clk write_flash (1) (1) (2) (2) (2) clk core clk i/o clk hsspi pll clock pll multi- -plexer cpu core flash & eeprom iox tn (1): iox includes: spi, usart, twi, aes, keyboard peripherals (2): tn indicates: timer0, timer1 and timer2. only timer2 can count using clk iox clock controller high speed spi block sci divider (by 8, 12, 16, 20, 24, 48, ...) clk prr1.prhsspi prr1.prsci prr1.prusb prr1.prscusb 1 1 1 1 0 0 0 0 sci smart card interface block x 1/2 clk usb usb usb host controller (default) prr0.pr (iox) 1 0 clk tn clk asy asy tn clock controller (default) prr0.pr (tx) 1 0 tosc1 t0 t1
at90scr100/116/132 42 tpr0327b ? vic ? 16fev11 7.1.1 8/16-bit risc cpu core clock - clk core the core clock is providing a clock to all the systems linked with the 8/16-bit risc cpu core. the cpu and some peripherals, such as timers, usart, spi, twi, keyboard interface and aes are directly connected to the clk core . clock divisions performed by the core divider will also affect clk i/o and clk tn (depending on the timer controller clock selection). please see ?clkpr ? clock prescale register? on page 40 for core divider access descriptions. 7.1.2 cpu clock - clk cpu the cpu clock is routed to parts of the syst em concerned with operation of the 8/16-bit risc cpu core. examples of such modules are the general purpose register file, the status regis- ter and the data memory holding the stack pointer. halting the cpu clock inhibits the core from performing general operations and calculations. 7.1.3 i/o clock - clk i/o the i/o clock is used by the majority of the i/o modules, like timer/counters, spi, and usart. the i/o clock is also used by the external inte rrupt module, but note that some external inter- rupts are detected by asynchronous logic, allowing such interrupts to be detected even if the i/o clock is halted. 7.1.4 memory clock - clk flash and clk write_flash the memory clock controls operation of the flash interface. the clk flash is usually active simultaneously with the cpu clock, and is used to read and execute code from flash, and read data from eeprom. the clk write_flash is generated independently, and is used for all flash and eeprom write proce- dures. the section ?rtc clock? on page 47 gives more information about this private clock. 7.1.5 asynchronous timer clock ? clk asy the asynchronous timer clock allows the asyn chronous timer/counter to be clocked directly from an external clock or an external 32 khz clock crystal. the dedicated clock domain allows this timer/counter to be used as a real-time counter even when the device is in sleep mode. 7.1.6 high-speed spi clock - clk hsspi the high-speed spi does not use the clk cpu . using the clk mux , through specific dividers, the high-speed spi can work to frequencies higher than cpu?s one. please see ?hsspiier - hsspi interrupt enable register? on page 303 , for details about divider description. note note you can choose to disable a peripheral by cutting the clock supplying it. this will reduce the consumption of the at90scr100/116/132. please refer to ?prr0 ? power reduction register 0? on page 54 and ?prr1 ? power reduction register 1? on page 55 . note note you can reduce at90scr100/116/132 consumpt ion by disabling the clock input into hsspi, if you don?t need this peripheral. see ?prr1 ? power reduction reg- ister 1? on page 55 for details.
43 tpr0327b ? vic ? 16fev11 7. clock system at90scr100/116/132 7.1.7 smart card interface clock - clk sci the smart card interface clock is generated from clk mux via a specific divider described in the section ?sciclk - smart card clock register? on page 213 . this means the scib is capable of operating at frequencies up to 12mhz. 7.1.8 usb clock - clk usb the usb module can only work if clk mux = clk pll . then, an automatic divider by 2 is applied to reach the 48 mhz. both usb device and usb host controller modules use clk usb . 7.2 clock sources at chip startup, clk mux = clk xtal . the external clock must be a 8mhz clock, and can be generated by either a crystal or an oscillator. the selection of the external clock source is done by a fuse as shown below: notes: 1. for all fuses ?1? means unprogrammed while ?0? means programmed. 7.2.1 default clock source the device is shipped in ?low power crystal oscillator? mode. the start-up time is set to maxi- mum and the time-out period enabled. even if the at90scr100/116/132 core has switched to clk pll , it can switch to clk xtal again by clearing the pllcr.pllmux bit. see ?pllcr ? phase lock loop (pll) control register? on page 48. 7.2.2 clock startup sequence any clock source needs a sufficient vcc to start oscillating and a minimum number of oscillating cycles before it can be considered stable. to ensure sufficient vcc, the device issues an internal reset with a time-out delay (t tout ) after the device reset is released by all other reset sources. the ?on-chip debug system? on page 57 describes the start conditions for the internal reset. the delay (t tout ) is timed from the watchdog oscillator and the number of cycles in the delay is set by the sutx and ckselx fuse bits. the note note you can reduce at90scr100/116/132 consumpt ion by disabling the clock input into scib, if you don?t need this peripheral. see ?prr1 ? power reduction regis- ter 1? on page 55 for details. note note you can reduce at90scr100/116/132 consumpt ion by disabling the clock input into usb device module and/or usb host module, if you don?t need these periph- erals. see ?prr1 ? power reduction register 1? on page 55 for details. table 7-1. device clocking options select (1) device clocking option cksel3 low power crystal oscillator 1 external clock 0
at90scr100/116/132 44 tpr0327b ? vic ? 16fev11 delay options are shown in table 7-2 . the frequency of the watchdog oscillator is voltage dependent. the main purpose of the delay is to keep the 8/16-bit risc cpu in reset until it is supplied with the minimum vcc. the delay will not monitor the actual voltage thus it will be required to select a delay longer than the vcc rise time. if this is not possible, an internal or external brown-out detection circuit should be used. a bod circuit will ensure sufficient vcc before it releases the reset, thus the time-out delay can be disabled. di sabling the time-out delay without utilizing a brown-out detection circuit is not recommended. the oscillator is required to oscillate for a minimum number of cycles before the clock is consid- ered stable. an internal ripple counter monitors the oscillator output clock, and keeps the internal reset active for a given number of clock cycl es. the reset is then released and the device will start to execute. the recommended oscillator start-up time is dependent on the clock type, and varies from 6 cycles for an externally applied clock to 32k cycles for a low frequency crystal. the start-up sequence for the clock includes both the time-out delay and the start-up time when the device starts up from reset. when starting up from power-save or power-down mode, vcc is assumed to be at a sufficient level and only the start-up time is included. 7.2.3 clock source connections the pins xtal1 and xtal2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in figure 7-2 . either a quartz crystal or a ceramic resonator may be used. c1 and c2 should always be equal for both crystals and resonators. for ceramic resonators, the capacitor values given by the manufacturer should be used. figure 7-2. crystal oscillator connections 7.2.3.1 low power crystal oscillator this crystal oscillator is a low power oscillator, with reduced voltage swing on the xtal2 out- put. it gives the lowest power consumption, but is not capable of driving other clock inputs. the only crystal supported by the at90scr100/116/132 is an 8mhz crystal. table 7-2. number of watchdog oscillator cycles typ time-out (v cc = 5.0v) typ time-out (v cc = 3.0v) number of cycles 0 ms 0 ms 0 4.1 ms 4.3 ms 512 65 ms 69 ms 8k (8,192) c1 = 10pf c2 = 10pf 8mhz
45 tpr0327b ? vic ? 16fev11 7. clock system at90scr100/116/132 the cksel0 fuse together with the sut1..0 fuses select the start-up times as shown in table 7-3 . notes: 1. these options should only be used if frequency stability at start-up is not important for the application. these options are not suitable for crystals. 2. these options are intended to be used with ceramic resonators and will ensure frequency sta- bility at start-up. 7.2.3.2 external clock to drive the device from an external clock source, xtal1 should be driven as shown in figure 7-3 . to run the device on an external clock, the cksel fuses must be programmed to ?0000?. figure 7-3. external clock drive configuration when this clock source is selected, start-up times are determined by the sut fuses as shown in table 7-4 . table 7-3. start-up times for the low power crystal oscillator clock selection oscillator source / power conditions start-up time from power-down and power-save additional delay from reset (v cc = 5.0v) cksel0 sut1..0 ceramic resonator, fast rising power 258 ck 14ck + 4.1 ms (1) 000 ceramic resonator, slowly rising power 258 ck 14ck + 49.6 m s (1) 001 ceramic resonator, bod enabled 1k ck 14ck (2) 010 ceramic resonator, fast rising power 1k ck 14ck + 3.1 ms (2) 011 ceramic resonator, slowly rising power 1k ck 14ck + 49.6 ms (2) 100 crystal oscillator, bod enabled 32k ck 14ck 1 01 crystal oscillator, fast rising power 32k ck 14ck + 3.1 ms 1 10 crystal oscillator, slowly rising power 32k ck 14ck + 65 ms 1 11 nc e xternal clock signal xtal2 xtal1 gnd
at90scr100/116/132 46 tpr0327b ? vic ? 16fev11 when applying an external clock, it is required to avoid sudden changes in the applied clock fre- quency to ensure stable operation of the mcu. a variation in frequency of more than 2% from one clock cycle to the next can lead to unpredictable behavior. if changes of more than 2% are required, ensure that the mcu is kept in reset during the changes. 7.2.4 pll clock the at90scr100/116/132?s pll is used to generate internal high frequency clock synchro- nized by an external low-frequency clock of 8mhz desribed in section ?clock sources? on page 43 . the pll block combines phase frequency comparator and lock detector. this block makes the comparison between a reference clock and a reverse clock and generates some pulses on the up or down signal depending on the edges of the reverse clock. enabling the pll by setting pllcr.on bit starts the stabilization process. as soon as the pll is locked, which means that the clock generated is stable, supporting a duty cycle of 50%, the pllcr.lock bit is set. when the pll is locked, it is now possible to switch the pll clock multiplexer to the pll clock, by setting the pllcr.pllmux bit. see ?pllcr ? phase lock loop (pll) control register? on page 48. it is highly recommended that the clk cpu dividers are changed before switching to the clk pll . table 7-4. start-up times for the external clock selection power conditions start-up time from power- down and power-save additional delay from reset (v cc = 5.0v) sut1..0 bod enabled 6 ck 14ck 00 fast rising power 6 ck 14ck + 4.1 ms 01 slowly rising power 6 ck 14ck + 65 ms 10 reserved 11 note note the system clock prescaler can be used to implement run-time changes of the internal clock frequency while still ensuring stable operation. refer to ?clkpr ? clock prescale register? on page 48 for details.
47 tpr0327b ? vic ? 16fev11 7. clock system at90scr100/116/132 figure 7-4. programming pll 7.2.5 rtc clock at90scr100/116/132 supports a rtc counting feature by using timer 2. the description of the real time counter is described section 13.3 ?8-bit timer/counter2 with pwm and asynchro- nous operation (rtc)? on page 142 . the external clock to connect to get a accurate rtc is a 32.768 khz clock. figure 7-5. rtc clock connection switch clk to clk pllcr.pllmux = 1 mux pll configure cpu divider clkpr = xxxxb enable pll pllcr.on = 1 no yes is pll locked ? pllcr.lock = 1 ? pll programming tosc1 c1 = 22pf c2 = 22pf tosc2 32.768 khz
at90scr100/116/132 48 tpr0327b ? vic ? 16fev11 7.3 clock output buffer the device can output the system clock clk core on the clko pin. to enable the output, the ckout fuse has to be programmed. this mode is suitable when the chip clock is used to drive other circuits on the system. the clock will also be output during reset, and the normal operation of the i/o pin will be overriden when the fuse is programmed. 7.4 clock system registers 7.4.1 pllcr ? phase lock loop (pll) control register ? bit 7 ? pllmux : pll clock multiplexer control bit set this bit (1) to switch clock multiplexer (clk mux ) to pll clock (clk pll ). clear this bit (0) to switch clk mux to external clock (clk xtal ). ? bit 6..2 ? reserved bits these bits are reserved for future use. ? bit 1 ? lock : pll lock bit signal this bit is set by hardware as soon as the clock generated by the pll (clk pll ) is stable. it is for- bidden to switch clk mux to clk pll if the lock bit is not set. wait for the pllcr.lock bit to be set before switching to clk pll using the pllmux bit. ? bit 0 ? on : pll start bit setting this bit (1) will start the pll. as soon as lock bit is set, you can switch on clk pll clock, not before. clearing this bit (0) will stop the pll. 7.4.2 clkpr ? clock prescale register bit 76543 2 10 $000062 pllmux---- -lockonpllcr read/write r/w r r r r r r r/w initial value 0 0 0 0 0 0 0 0 0x00 caution ! when the cpu runs on clk pll , and the pll is stopped, the cpu will be clocked no longer. this will freeze the cpu and only a reset will be able to start the cpu again. before stopping the pll, make sure that the cpu uses external clock clk xtal by using the pllmux register. bit 76543 2 10 $000061 ----clkps3clkps2clkps1clkps0clkpr read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
49 tpr0327b ? vic ? 16fev11 7. clock system at90scr100/116/132 ? bit 7..4 ? reserved bits these bits are reserved for future use. ? bits 3..0 ? clkps3..0 : clock prescaler select bits 3..0 these bits define the division factor between the selected clock source and the internal system clock. these bits can be written at run-time to vary the clock frequency to suit the application requirements. as the divider divides the master clock input to the mcu, the speed of all synchro- nous peripherals is reduced when a division fact or is used. the division factors are given in table 7-5 . you can change the clkpr on the fly. the divider will automatically be active. default value of clkpr is 0x00. notes: 1. clk mux =96mhz, clock generated by the pll 2. clk mux =8mhz, clock provided by external clock source xtal. 3. it is impossible for the cpu core to support 96mhz, thus, by default, the divide by one clock option generates a 16mhz clock. table 7-5. clock prescaler select (clk cpu ) clkps3 clkps2 clkps1 clkps0 clkpr clock division factor clk cpu ( clk mux = clk pll ) (1) clk cpu ( clk mux = clk xtal ) (2) 000 00x00 1 (3) 16mhz (3) 8mhz 000 10x01 4 24mhz 2mhz 0 0 1 0 0x02 5 19.2mhz 1.60mhz 0 0 1 1 0x03 6 16mhz 1.33mhz 010 00x04 8 12mhz 1mhz 0 1 0 1 0x05 12 8mhz 0.67mhz 0 1 1 0 0x06 24 4mhz 0.33mhz 0 1 1 1 0x07 48 2mhz 0.17mhz 1 0 0 0 0x08 96 1mhz 0.08mhz 100 10x09 reserved 101 00x0a 101 10x0b 110 00x0c 110 10x0d 111 00x0e 111 10x0f
at90scr100/116/132 50 tpr0327b ? vic ? 16fev11
51 tpr0327b ? vic ? 16fev11 8. power management and sleep modes at90scr100/116/132 8. power management and sleep modes sleep modes enable the application to shut down unused modules in the mcu, thereby saving power. the 8/16-bit risc cpu provides various sleep modes allowing the user to tailor the power consumption to the application?s requirements. to enter any of the five sleep modes, the se bit in the smcr must be written to logic one and a sleep instruction must be executed. the sm2, sm1, and sm0 bits in the smcr register select which sleep mode (idle, power-down, power-save, or standby) will be activated by the sleep instruction. see table 8-2 for a summary. if an enabled interrupt occurs while the mcu is in a sleep mode, the mcu wakes up. the mcu is then halted for four cycles in addition to the start- up time, executes the interrupt routine, and resumes execution from the instruction following sleep. the contents of the register file and sram are unaltered when the device wakes up from sleep. if a reset occurs during sleep mode, the mcu wakes up and executes from the reset vector. figure 7-1 on page 41 presents the different clock systems in the at90scr100/116/132, and their distribution. the figure is helpful in selecting an appropriate sleep mode. 8.1 power modes descriptions 8.1.1 idle mode when the sm2:0 bits are written to 000, the sleep instruction makes the mcu enter idle mode, stopping the cpu but allowing the peripherals and the interrupt system to continue operating. this sleep mode basically halts clk cpu and clk flash , while allowing the other clocks to run. idle mode enables the mcu to wake up from external triggered interrupts as well as internal ones like the timer overflow and usart transmit complete interrupts, as shown in table 8-1 . 8.1.2 power-down mode when the sm2:0 bits are written to 010, the sleep instruction makes the mcu enter power- down mode. in this mode, the external oscillator is stopped, while the external interrupts, the 2- wire serial interface, and the watchdog continue operating (if enabled). only an external reset, a coherent communication request on the different communication interface (twi, usb, hsspi, spi, usart), a card insertion/removal, an external interrupt, a pin change interrupt or a key- caution ! please refer to the section entitled ?important note about: entering and leaving low consumption modes? on page 56 , to read important remarks on achieving min- imum consumption. note note when waking up from power-down or power-save mode, there is a delay from when the wake-up condition occurs to when the wake-up becomes effective. this allows the clock to restart and become stable after having been stopped. the wake-up period is defined by the same cksel fuses that define the reset time- out period, as described in table 7-3 on page 45 .
at90scr100/116/132 52 tpr0327b ? vic ? 16fev11 board pin pressed interrupt can wake up the mcu. this sleep mode basically halts all generated clocks, allowing operation of asynchronous modules only. note that if a level triggered interrupt is used to wake-up from power-down mode, the changed level must be held for some time to wake up the mcu. refer to ?external interrupts? on page 77 for details. when waking up from power-down mode, there is a delay from when the wake-up condition occurs until when the wake-up becomes effective. this allows the clock to restart and become stable after having been stopped. the wake-up period is defined in table 7-3 . 8.1.3 power-save mode when the sm2:0 bits are written to 011, the sleep instruction makes the mcu enter power- save mode. this mode is identical to power-down, with one exception: if timer/counter2 is enabled, it will keep running during sleep. the device can wake up from either timer overflow or output compare event from timer/counter2 if the corresponding timer/counter2 interrupt enable bits are set in timsk2, and the global interrupt enable bit in sreg is set. if timer/counter2 is not running, power-down mode is recommended instead of power-save mode. the timer/counter2 can be clocked both synchronously and asynchronously in power-save mode. if the timer/counter2 is not using the asynchronous clock, the timer/counter oscillator is stopped during sleep. if the timer/counter2 is not using the synchronous clock, the clock source is stopped during sleep. note that even if the synchronous clock is running in power-save, this clock is only available for the timer/counter2. 8.1.4 standby mode when the sm2:0 bits are 110, the sleep instruction makes the mcu enter standby mode. this mode is identical to power-down with the except ion that the oscillator is kept running. from standby mode, the device wakes up in six clock cycles. caution ! to obtain a minimum consumption level, don?t forget to stop the dcdc and pll, as remarked in section ?important note about: entering and leaving low consump- tion modes? on page 56 .
53 tpr0327b ? vic ? 16fev11 8. power management and sleep modes at90scr100/116/132 8.1.5 extended standby mode when the sm2:0 bits are 111, the sleep instruction makes the mcu enter extended standby mode. this mode is identical to power-save mode with the exception that the oscillator is kept running. from extended standby mode, the device wakes up in six clock cycles. notes: 1. if timer/counter2 is running in asynchronous mode. 2. for int3:0, only level interrupt. 8.2 power reduction register the power reduction register, prr, provides a method to stop the clock to individual peripher- als to reduce power consumption. the current state of the peripheral is frozen and the i/o registers can not be read or written. resources used by the peripheral when stopping the clock will remain occupied, hence the peripheral should in most cases be disabled before stopping the clock. waking up a module, which is done by clearing the bit in prr, puts the module in the same state as before shutdown. 8.2.1 smcr ? sleep mode control register the sleep mode control register contains control bits for power management. ? bits 3..1 ? sm2..0 : sleep mode select bits 2..0 these bits select between the five available sleep modes as shown in table 8-2 . table 8-1. active clock domains and wake-up sources in the different sleep modes. active clock domains oscillators wake-up sources sleep mode clk cpu clk flash , clk sci clk i/o clk hsspi , clk usb clk asy main clock source enabled timer osc enabled int3:0 pin change coherent communication request timer2 spm/ eeprom ready keyboard pin pressed wdt interrupt other i/o idle xxxxx (1) xxxxxxx power-down x (2) xxx power-save x x (1) x (2) xx xx standby x x (2) xxx extended standby x (1) xx (1) x (2) xx xx bit 76543 2 10 0x33 (0x53) ----sm2sm1sm0sesmcr read/writerrrrr/wr/wr/wr/w initial value 0 0 0 0 0 0 0 0 0x00 table 8-2. sleep mode select sm2 sm1 sm0 sleep mode 000idle 001reserved 010power-down 011power-save 100reserved
at90scr100/116/132 54 tpr0327b ? vic ? 16fev11 note: 1. standby modes are only recommended for use with external crystals or resonators. ? bit 0 ? se: sleep enable the se bit must be written to logic one to make the mcu enter the sleep mode when the sleep instruction is executed. to avoid the mcu entering the sleep mode unless it is the programmer?s purpose, it is recommended to write the sleep enable (se) bit to one just before the execution of the sleep instruction and to clear it immediately after waking up. 8.2.2 prr0 ? power reduction register 0 the power reduction register allows the shut down of peripherals directly connected to cpu resources. these peripherals are activated by default and can be shut down for power con- sumption reasons if they are not used by an application. ? bit 7 - prtwi: power reduction twi writing a logic one to this bit shuts down the twi by stopping the clock to the module. when waking up the twi again, the twi should be re initialized to ensure proper operation. ? bit 6 - prtim2: power reduction timer/counter2 writing a logic one to this bit shuts down the timer/counter2 module in synchronous mode (as2 is 0). when the timer/counter2 is enabled, operation will continue like before the shutdown. ? bit 5 - prtim0: power reduction timer/counter0 writing a logic one to this bit shuts down the timer/counter0 module. when the timer/counter0 is enabled, operation will continue as before the shutdown. ? bit 4 - res: reserved bit reserved for future use and will always read as zero. ? bit 3 - prtim1: power reduction timer/counter1 writing a logic one to this bit shuts down the timer/counter1 module. when the timer/counter1 is enabled, operation will continue like before the shutdown. ? bit 2 - prspi: power reduction serial peripheral interface writing a logic one to this bit shuts down the serial peripheral interface by stopping the clock to the module. when waking up the spi again, the spi should be re initialized to ensure proper operation. ? bit 1 - prusart0: power reduction usart0 101reserved 1 1 0 standby (1) 1 1 1 extended standby (1) table 8-2. sleep mode select sm2 sm1 sm0 sleep mode bit 76543 2 1 0 $000064 prtwi prtim2 prtim0 - prtim1 prspi prusart0 - prr0 read/write r/w r/w r/w r r/w r/w r/w r initial value00000 0 0 00x00
55 tpr0327b ? vic ? 16fev11 8. power management and sleep modes at90scr100/116/132 writing a logic one to this bit shuts down the usart0 by stopping the clock to the module. when waking up the usart0 again, the usart0 should be reinitialized to ensure proper operation. ? bit 0 - res: reserved bit reserved for future use and will always read as zero. 8.2.3 prr1 ? power reduction register 1 the power reduction register allows the shut down of peripherals directly connected to cpu resources. these peripherals are activated by default and can be shut down for power con- sumption reasons if they are not used by an application. ? bit 7 - res: reserved bit reserved for future use and will always read as zero. ? bit 6 - res: reserved bit reserved for future use and will always read as zero. ? bit 5 - prkb: power reduction keyboard writing a logic one to this bit shuts down the keyboard module by stopping the clock to the mod- ule. when waking up the keyboard again, the keyboard should be re initialized to ensure proper operation. ? bit 4 - praes: power reduction aes writing a logic one to this bit shuts down the aes module by stopping the clock to the module. when waking up the aes again, the aes should be re initialized to ensure proper operation. ? bit 3 - prsci: power reduction smart card interface writing a logic one to this bit shuts down the smart card interface module by stopping the clock to the module. when waking up the scib again, the scib should be re initialized to ensure proper operation. ? bit 2 - prhsspi: power reduction high speed spi writing a logic one to this bit shuts down the high speed serial peripheral interface by stopping the clock to the module. when waking up the hsspi again, the hsspi should be re initialized to ensure proper operation. ? bit 1 - prusb: power reduction usb writing a logic one to this bit shuts down the usb by stopping the clock to the module. when waking up the usb again, the usb should be reinitialized to ensure proper operation. ? bit 0 - prusbh: power reduction usb host controller bit 76543 2 1 0 $000065 - - prkb praes prsci prhsspi prusb prusbh prr1 read/write r/w r/w r/w r r/w r/w r/w r initial value00000 0 0 00x00
at90scr100/116/132 56 tpr0327b ? vic ? 16fev11 writing a logic one to this bit shuts down the usb host controller by stopping the clock to the module. when waking up the usb host controller again, the usb host module should be reini- tialized to ensure proper operation. 8.3 important note about: entering a nd leaving low consumption modes 8.3.1 entering power down it is very important to note that there is no automatic switch to a low consumption mode for the pll clock multiplexer and for the dc/dc converter. ? to lower the powerdown consumption, the pll clock multiplexer must be switched to external clock and the pll must be stopped. to do so: ? switch from pll to external clock by clearing pllcr.pllmux. ? turn the pll off by clearing pllcr.on. ? wait until pllcr.lock bit is cleared. ? to lower the powerdown consumption, the dc/dc converter must also be switched off. to do so: ? clear dccr.dcon bit. this will generate a deactivation sequence. ? wait until dccr.dcrdy is cleared. 8.3.2 waking up from power down do not forget to restore the pll configuration and dc/dc converter when waking the chip up. please refer to figure 7-4 on page 47 and figure 16-1 on page 216 to re-enable these peripherals. 8.4 minimizing power consumption there are several issues to consider when trying to minimize the power consumption in a 8/16- bit risc cpu controlled system. in general, sleep modes should be used as much as possible, and the sleep mode should be selected so that as few as possible of the device?s functions are operating. all functions not needed should be disabled. in particular, the following modules may need special consideration when trying to achieve the lowest possible power consumption. 8.4.1 brown-out detector if the brown-out detector is not needed by the application, this module should be turned off. if the brown-out detector is enabled by the bodenable fuses, it will be enabled in all sleep modes, and hence, always consume power. in the deeper sleep modes, this will contribute sig- nificantly to the total current consumption. refer to ?brown-out detection? on page 62 for details on how to configure the brown-out detector. note note enabling the ?power reduction usb host controller? prevents the device from communicating with usb smart cards. however, if the smart card interface is on, communication with standard smart cards (iso7816 1-3) is still possible. to optimize the power consumption, if the application does not target usb smart card, the usb host controller should be disabled this way.
57 tpr0327b ? vic ? 16fev11 8. power management and sleep modes at90scr100/116/132 8.4.2 internal voltage reference the internal voltage reference will be enabled when needed by the brown-out detection. if this module is disabled as described in the sections above, the internal voltage reference will be dis- abled and it will not be consuming power. when turned on again, the user must allow the reference to start up before the output is used. if the reference is kept on in sleep mode, the out- put can be used immediately. refer to ?internal voltage reference? on page 63 for details on the start-up time. 8.4.3 watchdog timer if the watchdog timer is not needed in the applica tion, the module should be turned off. if the watchdog timer is enabled, it will be enabled in all sleep modes, and hence, always consume power. in the deeper sleep modes, this will contribute significantly to the total current consump- tion. refer to ?interrupts? on page 71 for details on how to configure the watchdog timer. 8.4.4 port pins when entering a sleep mode, all port pins should be configured to use minimum power. it is most important to ensure that no pins drive resi stive loads. this ensures that no power is con- sumed by the input logic when not needed. in so me cases, the input logic is needed to detect wake-up conditions, and it will then be enabled. refer to the section ?digital input enable and sleep modes? on page 89 for details on which pins are enabled. if the input buffer is enabled and the input signal is left floating or has an analog signal level close to v cc /2, the input buffer will use excessive power. 8.4.5 on-chip debug system if the on-chip debug system is enabled by the ocden fuse and the chip enters sleep mode, the main clock source is enabled, and hence, always consumes power. in the deeper sleep modes, this will contribute significantly to the total current consumption. there are three alternative ways to disable the ocd system: ? disable the ocden fuse. ? disable the jtagen fuse. ? write one to the jtd bit in mcucr. see ?mcucr ? mcu control register? on page 370.
at90scr100/116/132 58 tpr0327b ? vic ? 16fev11
59 tpr0327b ? vic ? 16fev11 9. system control and reset at90scr100/116/132 9. system control and reset 9.1 resetting the 8/16-bit risc cpu during reset, all i/o registers are set to their initial values, and the program starts execution from the reset vector. the instruction placed at the reset vector must be a jmp ? absolute jump ? instruction to the reset handling routine. if the program never enables an interrupt source, the interrupt vectors are not used, and regular program code can be placed at these locations. this is also the case if the reset vector is in the application section while the interrupt vectors are in the boot section or vice versa. the circuit diagram in figure 9-1 shows the reset logic. table 9-1 defines the electrical parameters of the reset circuitry. the i/o ports of the 8/16-bit risc cpu are immediately reset to their initial state when a reset source goes active. this does not require any clock source to be running. after all reset sources have gone inactive, a delay counter is invoked, stretching the internal reset. this allows the power to reach a stable level before normal operation starts. the time-out period of the delay counter is defined by the user through the sut fuses. the different selec- tions for the delay period are presented in table 7-3 . 9.2 reset sources the at90scr100/116/132 has five sources of reset: ? power-on reset. the mcu is reset when the supply voltage is below the power-on reset threshold (v pot ). ? external reset. the mcu is reset when a low level is present on the reset pin for longer than the minimum pulse length. ? watchdog reset. the mcu is reset when the watchdog timer period expires and the watchdog is enabled. ? brown-out reset. the mcu is reset when the supply voltage v cc is below the brown-out reset threshold (v bot ) and the brown-out detector is enabled. ? jtag 8/16-bit risc cpu reset. the mcu is reset as long as there is a logic one in the reset register, one of the scan chains of the jtag system. refer to the section ?ieee 1149.1 (jtag) boundary-scan? on page 367 for details.
at90scr100/116/132 60 tpr0327b ? vic ? 16fev11 figure 9-1. reset logic notes: 1. values are guidelines only. 2. the power-on reset will not work unless the supply voltage has been below v pot (falling) 9.2.1 power-on reset a power-on reset (por) pulse is generated by an on-chip detection circuit. the detection level is defined in table 9-1 . the por is activated whenever v cc is below the detection level. the por circuit can be used to trigger the start-up reset, as well as to detect a failure in supply voltage. a power-on reset (por) circuit ensures that the device is reset from power-on. reaching the power-on reset threshold voltage invokes the delay counter, which determines how long the table 9-1. reset characteristics (1) symbol parameter condition min typ max units v pot power-on reset threshold voltage (rising) 1.4 1.8 v power-on reset threshold voltage (falling) (2) 1.3 1.8 v v rst reset pin vil 0.2v cc v reset pin vih 0.85v cc mcu status register (mcusr) brown-out reset circuit bodlevel delay counters ck timeout wdrf borf extrf porf data bus clock controller spike filter pull-up resistor jtrf jtag reset register watchdog oscillator sut[1:0] power-on reset circuit
61 tpr0327b ? vic ? 16fev11 9. system control and reset at90scr100/116/132 device is kept in reset after v cc rise. the reset signal is activated again, without any delay, when v cc decreases below the detection level. figure 9-2. mcu start-up, reset tied to vcc figure 9-3. mcu start-up, reset extended externally 9.2.2 external reset an external reset is generated by a low level on the reset pin. reset pulses longer than the minimum pulse width (see table 9-1 ) will generate a reset, even if the clock is not running. shorter pulses are not guaranteed to generate a reset. when the applied signal reaches the reset threshold voltage ? v rst ? on its positive edge, the delay counter starts the mcu after the time-out period ? t tout ? has expired. figure 9-4. external reset during operation v reset time-out internal reset t tout v pot v rst cc reset time-out internal reset t tout v pot v rst v cc cc
at90scr100/116/132 62 tpr0327b ? vic ? 16fev11 9.2.3 brown-out detection at90scr100/116/132 has an on-chip brown-out detection (bod) circuit for monitoring the v cc level during operation by comparing it to a fixed trigger level. the bod can be activated or dis- abled by the bodenable fuses. the trigger level has a hysteresis to ensure spike free brown- out detection. the hysteresis on the detection level should be interpreted as v bot+ = v bot + v hyst /2 and v bot- = v bot - v hyst /2. when the bod is enabled, and v cc decreases to a value below the trigger level (v bot- in figure 9-5 ), the brown-out reset is immediately activated. when v cc increases above the trigger level (v bot+ in figure 9-5 ), the delay counter starts the mcu after the time-out period t tout has expired. the bod circuit will only detect a drop in v cc if the voltage stays below the trigger level for lon- ger than t bod given in table 9-1 . figure 9-5. brown-out reset during operation 9.2.4 watchdog reset when the watchdog times out, it will generate a short reset pulse of one ck cycle duration. on the falling edge of this pulse, the delay timer starts counting the time-out period t tout . refer to page 71 for details on operation of the watchdog timer. table 9-2. bodenable fuse coding bodenable fuse min v bot typ v bot max v bot 0bod disabled 1 2.3 v table 9-3. brown-out characteristics symbol parameter min typ max units v hyst brown-out detector hysteresis 50 mv t bod min pulse width on brown-out reset ns v cc reset t ime-out nternal reset v bot- v bot+ t tout
63 tpr0327b ? vic ? 16fev11 9. system control and reset at90scr100/116/132 figure 9-6. watchdog reset during operation 9.3 internal voltage reference at90scr100/116/132 features an internal bandgap reference. this reference is used for brown-out detection and supply monitor. 9.3.1 voltage reference enable signals and start-up time the voltage reference has a start-up time that may influence the way it should be used. the start-up time is given in table 9-4 . to save power, the reference is not always turned on. the reference is on during the following situations: 1. when the bod is enabled (by programming the bodenable fuse). 2. supply monitor is enabled (by programming the smoncr.smonen bit). to reduce power consumption in power-down mode, the user can avoid the two conditions above to ensure that the reference is turned off before entering power-down mode. notes: 1. values are guidelines only. 9.4 supply monitor this feature is designed to prevent the at 90scr100/116/132 operating under conditions that don?t guarantee a correct operation of its peripherals. useful to detect battery low voltage, the supply monitor peripheral generate an interruption when vcc drops below a level defined in table 9-5 . ck cc table 9-4. internal voltage reference characteristics (1) symbol parameter condition min typ max units t bg reference start-up time v cc = 2.7 t a = 25 c 40 70 s table 9-5. supply monitor references symbol parameter min typ max units v smon supply monitor level 2.5 v v smhyst supply monitor hysteresis 50 mv t smon min pulse width on brown-out reset ns
at90scr100/116/132 64 tpr0327b ? vic ? 16fev11 vcc shall be below supply monitor level for a minimum time before the interruption to be gener- ated. in the same behavior than bod, the supply monitor has an hysteresis to reach the level, interpreted as v smon+ = v smon + v smhyst /2 and v smon- = v smon - v smhyst /2 figure 9-7. supply monitor description please refer to section ?smoncr ? supply monitor control register? on page 68 and section ?interrupts? on page 71 for supply monitor interruption management. v cc reset interrupt trigger v smon- v smon+
65 tpr0327b ? vic ? 16fev11 9. system control and reset at90scr100/116/132 9.5 watchdog timer at90scr100/116/132 has an enhanced watchdog timer (wdt). the main features are: ? clocked from separate on-chip oscillator ? 3 operating modes ? interrupt ? system reset ? interrupt and system reset ? selectable time-out period from 16ms to 8s ? possible hardware fuse watchdog always on (wdton) for fail-safe mode figure 9-8. watchdog timer the watchdog timer (wdt) is a timer counting cycles of a separate on-chip 125 khz oscillator. the wdt gives an interrupt or a system reset when the counter reaches a given time-out value. in normal operation mode, it is required that the system uses the wdr - watchdog timer reset - instruction to restart the counter before the time-out value is reached. if the system doesn't restart the counter, an interrupt or system reset will be issued. in interrupt mode, the wdt gives an interrupt when the timer expires. this interrupt can be used to wake the device from sleep-modes, and also as a general system timer. one example is to limit the maximum time allowed for certain operations, giving an interrupt when the operation has run longer than expected. in system reset mode, the wdt gives a reset when the timer expires. this is typically used to prevent system hang-up in case of runaway code. the third mode, interrupt and system reset mode, combines the other two modes by first giving an inter- rupt and then switch to system reset mode. this mode will for instance allow a safe shutdown by saving critical parameters before a system reset. the watchdog always on (wdton) fuse, if programmed, will force the watchdog timer to sys- tem reset mode. with the fuse programmed the system reset mode bit (wde) and interrupt mode bit (wdie) are locked to 1 and 0 respectively. to further ensure program security, altera- tions to the watchdog set-up must follow timed sequences. the sequence for clearing the wde and changing the time-out configuration is as follows: 125khz oscillator osc/2k osc/4k osc/8k osc/16k osc/32k osc/64k osc/128k osc/256k osc/512k osc/1024k wdp0 wdp1 wdp2 wdp3 watchdog reset wde wdif wdie mcu reset interrupt
at90scr100/116/132 66 tpr0327b ? vic ? 16fev11 1. in the same operation, write a logic one to the watchdog change enable bit (wdce) and wde. a logic one must be written to wde regardless of the previous value of the wde bit. 2. within the next four clock cycles, write the wde and watchdog prescaler bits (wdp) as desired, but with the wdce bit cleared. this must be done in one operation. the following code example shows one assembly and one c function for turning off the watch- dog timer. the example assumes that interrupts are controlled (e.g. by disabling interrupts globally) so that no interrupts will occur during the execution of these functions. assembly code example wdt_off: ; turn off global interrupt cli ; reset watchdog timer wdr ; clear wdrf in mcusr in r16, mcusr andi r16, (0xff & (0< 67 tpr0327b ? vic ? 16fev11 9. system control and reset at90scr100/116/132 the following code example shows one assembly and one c function for changing the time-out value of the watchdog timer. note note if the watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the device will be reset and the watchdog timer will stay enabled. if the code is not set up to handle the watchdog, this might lead to an eternal loop of time-out resets. to avoi d this situation, the application software should always clear the watchdog system reset flag (wdrf) and the wde con- trol bit in the initialisation routine, even if the watchdog is not in use. assembly code example wdt_prescaler_change: ; turn off global interrupt cli ; reset watchdog timer wdr ; start timed sequence in r16, wdtcsr ori r16, (1< at90scr100/116/132 68 tpr0327b ? vic ? 16fev11 9.6 register description 9.6.1 mcusr ? mcu status register the mcu status register provides information on which reset source caused an mcu reset. ? bit 4 ? jtrf: jtag reset flag this bit is set if a reset is being caused by a logic one in the jtag reset register selected by the jtag instruction avr_reset. this bit is rese t by a power-on reset, or by writing a logic zero to the flag. ? bit 3 ? wdrf: watchdog reset flag this bit is set if a watchdog reset occurs. the bit is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 2 ? borf: brown-out reset flag this bit is set if a brown-out reset occurs. the bit is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 1 ? extrf: external reset flag this bit is set if an external reset occurs. the bit is reset by a power-on reset, or by writing a logic zero to the flag. ? bit 0 ? porf: power-on reset flag this bit is set if a power-on reset occurs. the bit is reset only by writing a logic zero to the flag. to make use of the reset flags to identify a reset condition, the user should read and then reset the mcusr as early as possible in the program. if the register is cleared before another reset occurs, the source of the reset can be found by examining the reset flags. 9.6.2 smoncr ? supply monitor control register ? bit 7 ? smonif: supply monitor interrupt flag this bit is set by hardware when the external voltage vcc drops below a supply monitor level. if smonie and sreg.i bits are set, then an interrupt is triggered. this interrupt should allow time to save important information, or cancel critical exchanges. this bit must be cleared by software. ? bit 6 ? smonie: supply monitor interrupt enable bit 76543 2 10 0x34 (0x54) - - - jtrf wdrf borf extrf porf mcusr read/write r r r r/w r/w r/w r/w r/w initial value see bit description bit 76543 2 10 0x0063 smonif smonie - - - - - smonen smoncr read/write r/w r/w r r r r r r/w initial value 0 0 0 0 0 0 0 0 0x00
69 tpr0327b ? vic ? 16fev11 9. system control and reset at90scr100/116/132 this bit is set and cleared by software. set this bit to enable interrupt generation as soon as vcc drops below the supply monitor level. the global interrupt bit (sreg.i) should be set. clear this bit to mask supply monitor interruption generation. ? bit 5..1 ? reserved bits these bits are reserved for future use. ? bit 0 ? smonen: supply monitor enable this bit is set and cleared by software. setting this bit will activate the supply monitor system. clearing this bit will disable the supply monitor system and reduce power consumption. 9.6.3 wdtcsr ? watchdog timer control register ? bit 7 - wdif: watchdog interrupt flag this bit is set when a time-out occurs in the watchdog timer and the watchdog timer is config- ured for interrupt. wdif is cleared by hardw are when executing the corresponding interrupt handling vector. alternatively, wdif is cleared by writing a logic one to the flag. when the i-bit in sreg and wdie are set, the watchdog time-out interrupt is executed. ? bit 6 - wdie: watchdog interrupt enable when this bit is written to one and the i-bit in the status register is set, the watchdog interrupt is enabled. if wde is cleared in combination with this setting, the watchdog timer is in interrupt mode, and the corresponding interrupt is executed if a time-out in the watchdog timer occurs. if wde is set, the watchdog timer is in interrupt and system reset mode. the first time-out in the watchdog timer will set wdif. executing the corresponding interrupt vector will clear wdie and wdif automatically by hardware (the watchdog goes to system reset mode). this is use- ful for keeping the watchdog timer security while using the interrupt. to stay in interrupt and system reset mode, wdie must be set after each interrupt. this should however not be done within the interrupt service routine itself, as this might compromise the safety-function of the watchdog system reset mode. if the interrupt is not executed before the next time-out, a sys- tem reset will be applied. notes: 1. wdton is a fuse bit (see ?fuse high byte? on page 393) . bit 76543 2 10 $000060 wdif wdie wdp3 wdce wde wdp2 wdp1 wdp0 wdtcsr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 table 9-6. watchdog timer configuration wdton (1) wde wdie mode action on time-out 0 0 0 stopped none 0 0 1 interrupt mode interrupt 0 1 0 system reset mode reset 011 interrupt and system reset mode interrupt, then go to system reset mode 1 x x system reset mode reset
at90scr100/116/132 70 tpr0327b ? vic ? 16fev11 ? bit 4 - wdce: watchdog change enable this bit is used in timed sequences for changing wde and prescaler bits. to clear the wde bit, and/or change the prescaler bits, wdce must be set. once written to one, hardware will clear wdce after four clock cycles. ? bit 3 - wde: watchdog system reset enable wde is overridden by wdrf in mcusr. this means that wde is always set when wdrf is set. to clear wde, wdrf must be cleared first. this feature ensures multiple resets during con- ditions causing failure, and a safe start-up after the failure. ? bit 5, 2..0 - wdp3..0: watchdog timer prescaler 3..0 the wdp3:0 bits determine the watchdog timer prescaling when the watchdog timer is run- ning. the different prescaling values and thei r corresponding time-out periods are shown in table 9-7 on page 70 .. note: 1. 85khz oscillator used for max time-out table 9-7. watchdog timer prescale select wdp3 wdp2 wdp1 wdp0 number of wdt oscillator cycles max time-out at v cc = 5.0v (1) 0 0 0 0 2k (2048) cycles 24.1 ms 0 0 0 1 4k (4096) cycles 48.2 ms 0 0 1 0 8k (8192) cycles 96.4 ms 0 0 1 1 16k (16384) cycles 0.19 s 0 1 0 0 32k (32768) cycles 0.39 s 0 1 0 1 64k (65536) cycles 0.77 s 0 1 1 0 128k (131072) cycles 1.54 s 0 1 1 1 256k (262144) cycles 3.1 s 1 0 0 0 512k (524288) cycles 6.2 s 1 0 0 1 1024k (1048576) cycles 12.3 s 1010 reserved 1011 1100 1101 1110 1111
71 tpr0327b ? vic ? 16fev11 10. interrupts at90scr100/116/132 10. interrupts this section describes the specifics of the interrupt handling as performed in at90scr100/116/132. for a general explanation of the 8/16-bit risc cpu interrupt handling, refer to ?reset and interrupt handling? on page 28 . 10.1 interrupt vectors in at90scr100/116/132 table 10-1. reset and interrupt vectors vector no. program address (1) source interrupt definition 1 $0000 (2) reset external pin, power-on reset, brown-out reset, watchdog reset, and jtag 8/16-bit risc cpu reset 2 $0002 int0 external interrupt request 0 3 $0004 int1 external interrupt request 1 4 $0006 int2 external interrupt request 2 5 $0008 int3 external interrupt request 3 6 $000a pcint0 pin change interrupt request 0 7 $000c pcint1 pin change interrupt request 1 8 $000e pcint2 pin change interrupt request 2 9 $0010 wdt watchdog time-out interrupt 10 $0012 timer2_compa timer/counter2 compare match a 11 $0014 timer2_compb timer/counter2 compare match b 12 $0016 timer2_ovf timer/counter2 overflow 13 $0018 timer1_capt timer/counter1 capture event 14 $001a timer1_compa timer/counter1 compare match a 15 $001c timer1_compb timer/counter1 compare match b 16 $001e timer1_ovf timer/counter1 overflow 17 $0020 timer0_compa timer/counter0 compare match a 18 $0022 timer0_compb timer/counter0 compare match b 19 $0024 timer0_ovf timer/counter0 overflow 20 $0026 spi_stc spi serial transfer complete 21 $0028 usart_rx usart rx complete 22 $002a usart_udre usart data register empty 23 $002c usart_tx usart tx complete 24 $002e supply_mon supply monitor interruption 25 -- rfu reserved for future use 26 $0032 ee_ready eeprom ready 27 $0034 twi 2-wire serial interface 28 $0036 spm_ready store program memory ready 29 $0038 keyboard keyboard input changed
at90scr100/116/132 72 tpr0327b ? vic ? 16fev11 notes: 1. when the ivsel bit in mcucr is set, interrupt vectors will be moved to the start of the boot flash section. the address of each interrupt vector will then be the address in this table added to the start address of the boot flash section. 2. when the bootrst fuse is programmed, the device will jump to the boot loader address at reset, see ?memory programming? on page 391 . table 10-2 shows reset and interrupt vectors placement for the various combinations of bootrst and ivsel settings. if the program never enables an interrupt source, the interrupt vectors are not used, and regular program code c an be placed at these locations. this is also the case if the reset vector is in the application section while the interrupt vectors are in the boot section or vice versa. note: 1. the boot reset address is shown in table 28-7 on page 390 . for the bootrst fuse ?1? means unprogrammed while ?0? means programmed. the most typical and general program setup for the reset and interrupt vector addresses in at90scr100/116/132 is: 30 $003a aes aes block operation ended 31 $003c hsspi high-speed spi interface 32 $003e usb endpoint usb endpoint linked interrupt 33 $0040 usb protocol usb protocol interrupt 34 $0042 scib smart card reader interface 35 $0044 usb host control usb host controller interrupt 36 $0046 usb host pipe usb host pipe interrupt 37 $0048 cpres card presence detection 38 $004a pcint3 pin change interrupt request 3 table 10-2. reset and interrupt vectors placement (1) bootrst ivsel reset address interrupt vectors start address 1 0 0x0000 0x0002 1 1 0x0000 boot reset address + 0x0002 0 0 boot reset address 0x0002 0 1 boot reset address boot reset address + 0x0002 table 10-1. reset and interrupt vectors (continued) vector no. program address (1) source interrupt definition addr ess labels code comments 0x jmp reset ; reset handler 0x02 jmp int0 ; irq0 handler 0x04 jmp int1 ; irq1 handler 0x06 jmp int2 ; irq2 handler 0x08 jmp int3 ; irq3 handler 0x0a jmp pcint0 ; pcint0 handler 0x0c jmp pcint1 ; pcint1 handler 0x0e jmp pcint2 ; pcint2 handler 0x10 jmp wdt ; watchdog timeout handler
73 tpr0327b ? vic ? 16fev11 10. interrupts at90scr100/116/132 when the bootrst fuse is unprogrammed, the boot section size set to 8k bytes and the ivsel bit in the mcucr register is set before any interrupts are enabled, the most typical and general program setup for the reset and interrupt vector addresses is: address labels code comments 0x00000 reset: ldi r16,high(ramend); main program start 0x00001 out sph,r16 ; set stack pointer to top of ram 0x00002 ldi r16,low(ramend) 0x12 jmp tim2_compa ; timer2 comparea handler 0x14 jmp tim2_compb ; timer2 compareb handler 0x16 jmp tim2_ovf ; timer2 overflow handler 0x18 jmp tim1_capt ; timer1 capture handler 0x1a jmp tim1_compa ; timer1 comparea handler 0x1c jmp tim1_compb ; timer1 compareb handler 0x1e jmp tim1_ovf ; timer1 overflow handler 0x20 jmp tim0_compa ; timer0 comparea handler 0x22 jmp tim0_compb ; timer0 compareb handler 0x24 jmp tim0_ovf ; timer0 overflow handler 0x26 jmp spi_stc ; spi transfer complete 0x28 jmp usart0_rxc ; usart0 rx complete handler 0x2a jmp usart0_udre ; usart0,udr empty handler 0x2c jmp usart0_txc ; usart0 tx complete handler 0x2e jmp supply_mon ; vcc dropped too low 0x30 jmp no_vect ; vector forbidden 0x32 jmp ee_rdy ; eeprom ready handler 0x34 jmp twi ; 2-wire serial handler 0x36 jmp spm_rdy ; spm ready handler 0x38 jmp keyboard ; keyboard handler 0x3a jmp aes ; crypto aes handler 0x3c jmp hsspi ; highspi it handler 0x3e jmp usb_endpoint ; usb endpoint it handler 0x40 jmp usb_protocol ; usb protocol it handler 0x42 jmp scib ; smart card interface it 0x44 jmp usb_host_ctl ; usb host controller it 0x46 jmp usb_host_pipe ; usb host pipe it 0x48 jmp cpres ; card inserted/removed 0x4a jmp pcint3 ; pcint3 handler ; 0x3e reset: ldi r16, high(ramend) ; main program start 0x3f out sph,r16 ; set stack pointer to top of ram 0x40 ldi r16, low(ramend) 0x41 out spl,r16 0x42 sei ; enable interrupts 0x43 xxx ... ... ... ...
at90scr100/116/132 74 tpr0327b ? vic ? 16fev11 0x00003 out spl,r16 0x00004 sei ; enable interrupts 0x00005 xxx ; .org 0x1f002 0x1f002 jmp ext_int0 ; irq0 handler 0x1f004 jmp ext_int1 ; irq1 handler ... ... ... ; 0x1fo36 jmp spm_rdy ; spm ready handler when the bootrst fuse is programmed and the boot section size set to 8k bytes, the most typical and general program setup for the reset and interrupt vector addresses is: address labels code comments .org 0x0002 0x00002 jmp ext_int0 ; irq0 handler 0x00004 jmp ext_int1 ; irq1 handler ... ... ... ; 0x00036 jmp spm_rdy ; spm ready handler ; .org 0x1f000 0x1f000 reset: ldi r16,high(ramend); main program start 0x1f001 out sph,r16 ; set stack pointer to top of ram 0x1f002 ldi r16,low(ramend) 0x1f003 out spl,r16 0x1f004 sei ; enable interrupts 0x1f005 xxx when the bootrst fuse is programmed, the boot section size set to 8k bytes and the ivsel bit in the mcucr register is set before any interrupts are enabled, the most typical and general program setup for the reset and interrupt vector addresses is: address labels code comments ; .org 0x1f000 0x1f000 jmp reset ; reset handler 0x1f002 jmp ext_int0 ; irq0 handler 0x1f004 jmp ext_int1 ; irq1 handler ... ... ... ; 0x1f036 jmp spm_rdy ; spm ready handler ; 0x1f03e reset: ldi r16,high(ramend); main program start 0x1f03f out sph,r16 ; set stack pointer to top of ram 0x1f040 ldi r16,low(ramend) 0x1f041 out spl,r16 0x1f042 sei ; enable interrupts 0x1fo43 xxx
75 tpr0327b ? vic ? 16fev11 10. interrupts at90scr100/116/132 10.1.1 moving interrupts between application and boot space the general interrupt control register controls the placement of the interrupt vector table. 10.1.2 mcucr ? mcu control register ? bit 7..2 ? different bits these bits are used by other functions of the 8/16-bit risc cpu core, or are reserved bits. ? bit 1 ? ivsel: interrupt vector select when the ivsel bit is cleared (zero), the interrupt vectors are placed at the start of the flash memory. when this bit is set (one), the interrupt vectors are moved to the beginning of the boot loader section of the flash. the actual address of the start of the boot flash section is deter- mined by the bootsz fuses. refer to the section ?memory programming? on page 391 for details. to avoid unintentional changes of interrupt vector tables, a special write procedure must be followed to change the ivsel bit: 1. write the interrupt vector change enable (ivce) bit to one. 2. within four cycles, write the desired value to ivsel while writing a zero to ivce. interrupts will automatically be disabled while this sequence is executed. interrupts are disabled in the cycle ivce is set, and they remain disabled until after the instruction following the write to ivsel. if ivsel is not written, interrupts remain disabled for four cycles. the i-bit in the status register is unaffected by the automatic disabling. ? bit 0 ? ivce: interrupt vector change enable the ivce bit must be written to logic one to enable change of the ivsel bit. ivce is cleared by hardware four cycles after it is written or when ivsel is written. setting the ivce bit will disable interrupts, as explained in the ivsel description above. see code example below. bit 76543210 0x35 (0x55) jtd - - pud - - ivsel ivce mcucr read/write r/w r r r/w r r r/w r/w initial value000000000x00 note note if interrupt vectors are placed in the boot loader section and boot lock bit blb02 is programmed, interrupts are disabled while executing from the application sec- tion. if interrupt vectors are placed in the application section and boot lock bit blb12 is programed, interrupts are disabled while executing from the boot loader section. refer to the section ?memory programming? on page 391 for details on boot lock bits.
at90scr100/116/132 76 tpr0327b ? vic ? 16fev11 assembly code example move_interrupts: ; get mcucr in r16, mcucr mov r17, r16 ; enable change of interrupt vector ori r16, (1< 77 tpr0327b ? vic ? 16fev11 11. external interrupts at90scr100/116/132 11. external interrupts the external interrupts are triggered by the int3:0 pin or any of the pcint31:0 pins. observe that, if enabled, the interrupts will trigger even if the int3:0 or pcint31:0 pins are configured as outputs. this feature provides a way of generating a software interrupt. the pin change interrupt pci3 will trigger if any enabled pcint31:24 pin toggles, pin change interrupt pci2 will trigger if any enabled pcint23:16 pin toggles, pin change interrupt pci1 will trigger if any enabled pcint15:8 pin toggles and pin change interrupt pci0 will trigger if any enabled pcint7:0 toggles. pcmsk3, pcmsk2 , pcmsk1 and pcmsk0 registers control which pins contribute to the pin change interrupts. pin change interrupts on pcint31:0 are detected asynchronously. this implies that these interrupts can also be used for waking the part from sleep modes other than idle mode. the external interrupts can be triggered by a falling or rising edge or a low level. this is set up as indicated in the specificati on for the external interrupt control registers ? eicra (int3:0). when the external interrupt is enabled and is configured as level triggered, the interrupt will trig- ger as long as the pin is held low. low level interrupts and the edge interrupt on int3:0 are detected asynchronously. this implies that these interrupts can be used for waking the part also from sleep modes other than idle mode. the i/o clock is halted in all sleep modes except idle mode. finally, as the int2 and int3 pins, are configured to pb0 and pb1 respectively and these port bits are multiplexed with other outputs, there is a way to use other pins to trigger int2 and int3. these pins are identified int2b and int3b (pins pc0 and pc1). refer to ?eirr ? external inter- rupt redirection register? on page 79 for more information. 11.1 external interrupt registers 11.1.1 eicra ? external interrupt control register a the external interrupt control register a contains control bits for interrupt sense control. ? bits 7..0 ? isc31, isc30 ? isc00, isc00 : external interrupt 3 - 0 sense control bits the external interrupts 3 - 0 are activated by the external pins int3:0 if the sreg i-flag and the corresponding interrupt mask in the eimsk is set. the level and edges on the external pins that activate the interrupts are defined in table 11-1 . edges on int3:0 are registered asynchro- nously. pulses on int3:0 pins wider than the minimum pulse width given in table 11-2 will generate an interrupt. shorter pulses are not guaranteed to generate an interrupt. if a low level interrupt is selected, the low level must be held until the completion of the currently executing instruction to generate an interrupt. if enabled, a level triggered interrupt will generate an inter- rupt request as long as the pin is held low. when changing the iscn bit, an interrupt can occur. note note if a level triggered interrupt is used for wake-up from power-down, the required level must be held long enough for the mcu to complete the wake-up to trigger the level interrupt. if the level disappears before the end of the start-up time, the mcu will still wake up, but no interrupt will be generated.. bit 76543210 $000069 isc31 isc30 isc21 isc20 isc11 isc10 isc01 isc00 eicra read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value000000000x00
at90scr100/116/132 78 tpr0327b ? vic ? 16fev11 therefore, it is recommended to first disable intn by clearing its interrupt enable bit in the eimsk register. then, the iscn bit can be changed. finally, the intn interrupt flag should be cleared by writing a logical one to its interrupt flag bit (intfn) in the eifr register before the interrupt is re-enabled. note: 1. n = 3, 2, 1or 0. when changing the iscn1/iscn0 bits, the interrupt must be disabled by clearing its interrupt enable bit in the eimsk register. otherwise an interrupt can occur when the bits are changed 11.1.2 eimsk ? external interrupt mask register ? bits 3..0 ? int3..0 : external interrupt request 3 - 0 enable when an int3:0 bit is written to one and the i-bit in the status register (sreg) is set (one), the corresponding external pin interrupt is enabled. the interrupt sense control bits in the external interrupt control register, eicra, defines whether the external interrupt is activated on rising or falling edge or level sensed. activity on any of these pins will trigger an interrupt request even if the pin is enabled as an output. this provides a way of generating a software interrupt. 11.1.3 eifr ? external interrupt flag register ? bits 3..0 ? intf3..0 : external interrupt flags 3 - 0 when an edge or logic change on the int3:0 pin triggers an interrupt request, intf3:0 becomes set (one). if the i-bit in sreg and the corresponding interrupt enable bit, int3:0 in eimsk, are set (one), the mcu will jump to the interrupt vector. the flag is cleared when the interrupt routine table 11-1. interrupt sense control (1) iscn1 iscn0 description 0 0 the low level of intn generates an interrupt request. 0 1 any edge of intn generates asynchronously an interrupt request. 1 0 the falling edge of intn generates asynchronously an interrupt request. 1 1 the rising edge of intn generates asynchronously an interrupt request. table 11-2. asynchronous external interrupt characteristics symbol parameter condition min typ max units t int minimum pulse width for asynchronous external interrupt 50 ns bit 76543210 0x1d (0x3d) ----int3int2int1int0eimsk read/writerrrrr/wr/wr/wr/w initial value000000000x00 bit 76543210 0x1c (0x3c) ----intf3intf2intf1intf0eifr read/writerrrrr/wr/wr/wr/w initial value000000000x00
79 tpr0327b ? vic ? 16fev11 11. external interrupts at90scr100/116/132 is executed. alternatively, the flag can be cleared by writing a logical one to it. these flags are always cleared when int3:0 are configured as level interrupt. 11.1.4 eirr ? external interrupt redirection register ? bit 3 ? intd3 : external interruption 3 direction this bit is set and cleared by software. please see the table below for bit description: ? bit 2 ? intd2 : external interruption 2 direction this bit is set and cleared by software. 11.1.5 pcicr ? pin change interrupt control register ? bit 3 ? pcie3 : pin change interrupt enable 3 when the pcie3 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 3 is enabled. any change on any enabled pcint31:24 pin will cause an inter- rupt. the corresponding interrupt of the pin change interrupt request is executed from the pci3 interrupt vector. pcint31:24 pins are enabled individually by the pcmsk3 register. ? bit 2 ? pcie2 : pin change interrupt enable 2 when the pcie2 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 2 is enabled. any change on any enabled pcint23:16 pin will cause an inter- note note when entering sleep mode with the int3:0 interrupts disabled, the input buffers on these pins will be disabled. this may cause a logic change in internal signals which will set the intf3:0 flags. see ?digital input enable and sleep modes? on page 89 for more information. bit 76543210 0x1a (0x3a) ----intd3intd2--eirr read/writerrrrr/wr/wrr initial value000000000x00 table 11-3. external interruption 3 pad location intd3 interruption 3 pad description 0 pb1 int3 active, int3b inactive 1 pc1 int3 inactive, int3b active table 11-4. external interruption 2 pad location intd3 interruption 3 pad description 0 pb0 int2 active, int2b inactive 1 pc0 int2 inactive, int2b active bit 76543210 0x68 ----pcie3pcie2pcie1pcie0pcicr read/writerrrrr/wr/wr/wr/w initial value000000000x00
at90scr100/116/132 80 tpr0327b ? vic ? 16fev11 rupt. the corresponding interrupt of the pin change interrupt request is executed from the pci2 interrupt vector. pcint23:16 pins are enabled individually by the pcmsk2 register. ? bit 1 ? pcie1 : pin change interrupt enable 1 when the pcie1 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 1 is enabled. any change on any enabled pcint15:8 pin will cause an inter- rupt. the corresponding interrupt of the pin change interrupt request is executed from the pci1 interrupt vector. pcint15:8 pins are enabled individually by the pcmsk1 register. ? bit 0 ? pcie0 : pin change interrupt enable 0 when the pcie0 bit is set (one) and the i-bit in the status register (sreg) is set (one), pin change interrupt 0 is enabled. any change on any enabled pcint7:0 pin will cause an interrupt. the corresponding interrupt of the pin change interrupt request is executed from the pci0 interrupt vector. pcint7:0 pins are enabled individually by the pcmsk0 register. 11.1.6 pcifr ? pin change interrupt flag register ? bit 3? pcif3 : pin change interrupt flag 3 when a logic change on any pcint31:24 pin triggers an interrupt request, pcif3 becomes set (one). if the i-bit in sreg and the pcie3 bit in pcicr are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cleared when the interrupt routine is executed. alter- natively, the flag can be cleared by writing a logical one to it. ? bit 2 ? pcif2 : pin change interrupt flag 2 when a logic change on any pcint23:16 pin triggers an interrupt request, pcif2 becomes set (one). if the i-bit in sreg and the pcie2 bit in pcicr are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cleared when the interrupt routine is executed. alter- natively, the flag can be cleared by writing a logical one to it. ? bit 1 ? pcif1 : pin change interrupt flag 1 when a logic change on any pcint15:8 pin triggers an interrupt request, pcif1 becomes set (one). if the i-bit in sreg and the pcie1 bit in pcicr are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cleared when the interrupt routine is executed. alter- natively, the flag can be cleared by writing a logical one to it. ? bit 0 ? pcif0 : pin change interrupt flag 0 when a logic change on any pcint7:0 pin triggers an interrupt request, pcif0 becomes set (one). if the i-bit in sreg and the pcie0 bit in pcicr are set (one), the mcu will jump to the corresponding interrupt vector. the flag is cleared when the interrupt routine is executed. alter- natively, the flag can be cleared by writing a logical one to it. bit 76543210 0x1b (0x3b) ----pcif3pcif2pcif1pcif0pcifr read/writerrrrrr/wr/wr/w initial value000000000x00
81 tpr0327b ? vic ? 16fev11 11. external interrupts at90scr100/116/132 11.1.7 pcmsk3 ? pin change mask register 3 ? bit 7..0 ? pcint31..24 : pin change enable mask 31..24 each pcint31:24 bit selects whether the pin change interrupt is enabled on the corresponding i/o pin. if pcint31:24 is set and the pcie3 bit in pcicr is set, the pin change interrupt is enabled on the corresponding i/o pin. if pcint31:24 is cleared, the pin change interrupt on the corresponding i/o pin is disabled. 11.1.8 pcmsk2 ? pin change mask register 2 ? bit 7..0 ? pcint23..16 : pin change enable mask 23..16 each pcint23:16-bit selects whether the pin change interrupt is enabled on the corresponding i/o pin. if pcint23:16 is set and the pcie2 bit in pcicr is set, the pin change interrupt is enabled on the corresponding i/o pin. if pcint23:16 is cleared, the pin change interrupt on the corresponding i/o pin is disabled. 11.1.9 pcmsk1 ? pin change mask register 1 ? bit 7..0 ? pcint15..8 : pin change enable mask 15..8 each pcint15:8-bit selects whether the pin change interrupt is enabled on the corresponding i/o pin. if pcint15:8 is set and the pcie1 bit in pcicr is set, the pin change interrupt is enabled on the corresponding i/o pin. if pcint15:8 is cleared, the pin change interrupt on the corresponding i/o pin is disabled. 11.1.10 pcmsk0 ? pin change mask register 0 ? bit 7..0 ? pcint7..0: pin change enable mask 7..0 each pcint7:0 bit selects whether the pin change interrupt is enabled on the corresponding i/o pin. if pcint7:0 is set and the pcie0 bit in pcicr is set, the pin change interrupt is enabled on bit 76543210 0x000073 pcint31 pcint30 pcint29 pcint28 pcin t27 pcint26 pcint25 pcint24 pcmsk3 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value000000000x00 bit 76543210 0x00006d pcint23 pcint22 pcint21 pcint20 pcin t19 pcint18 pcint17 pcint16 pcmsk2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value000000000x00 bit 76543210 0x00006c pcint15 pcint14 pcint13 pcint12 pc int11 pcint10 pcint9 pcint8 pcmsk1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value000000000x00 bit 76543210 0x00006b pcint7 pcint6 pcint5 pcint4 pcint3 pcint2 pcint1 pcint0 pcmsk0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value000000000x00
at90scr100/116/132 82 tpr0327b ? vic ? 16fev11 the corresponding i/o pin. if pcint7:0 is cleared, the pin change interrupt on the corresponding i/o pin is disabled.
83 tpr0327b ? vic ? 16fev11 12. i/o ports at90scr100/116/132 12. i/o ports 12.1 standard io ports all 8/16-bit risc cpu 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 uninten- tionally changing the direction of any other pi n with the sbi and cbi instructions. the same applies when changing drive value (if configured as output) or enabling/disabling of pull-up resis- tors (if configured as input). each output buffer has symmetrical drive characteristics with both high sink and source capability. the pin driver is strong enough to drive led displays directly. all port pins have individually selectable pull-up resistors with a supply-voltage invariant resistance. all i/o pins have protection diodes to both v cc and ground as indicated in figure 12-1 . refer to ?electrical characteristics? on page 423 for a complete list of parameters. figure 12-1. i/o pin equivalent schematic all registers and bit references in this section are written in general form. a lower case ?x? repre- sents the reference letter for the port, and a lower case ?n? represents the bit number. however, when using the register or bit defines in a program, the precise form must be used. for example, portb3 for bit no. 3 in port b, here documented generally as portxn. the physical i/o regis- ters and bit locations are listed in ?register description for i/o-ports? on page 91 . three i/o memory address locations are allocated for each port, one each for the data register ? portx, data direction register ? ddrx, and the port input pins ? pinx. the port input pins i/o location is read only, while the data register and the data direction register are read/write. however, writing a logic one to a bit in the pinx register, will result in a toggle in the correspond- ing bit in the data register. in addition, the pull-up disable ? pud bit in mcucr disables the pull-up function for all pins in all ports when set. using the i/o port as general digital i/o is described in ?ports as general digital i/o? on page 85 . most port pins are multiplexed with alter nate functions for the peripheral features on the device. to get a full description of the different pin configuration, refer to ?pin list configuration? on page 15 . note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port as general digital i/o. c pin logic r pu see figure "general digital i/o" for details pxn
at90scr100/116/132 84 tpr0327b ? vic ? 16fev11 12.2 specific low speed keyboard output to avoid abusive emc generation, at90scr100/116/132 embeds specific low speed output pads. figure 12-2. low-speed output schematic the current limitation of the ctrl block requires a polarisation current of about 250 a. this block is automatically disabled in power-down, power-save, standby and extended standby modes. these pads only concern kbon pins located on port pe [0..7]. see ?pin list configuration? on page 15. 12.3 led at90scr100/116/132 supports specific ports driving current to allow easy control of led dis- plays. figure 12-3. led source current n power management control smcr + cpu status port latch data kbon ctrl n nmos weak n port latch data ledn.0 ledn.1 pin ledcr n nmos
85 tpr0327b ? vic ? 16fev11 12. i/o ports at90scr100/116/132 notes: 1. when led control disabled, a current of ~8ma is provided on the port. 12.3.1 ledcr - led control register ? bit 7..6, 5..4, 3..2, 1..0 - ledn [1..0]: led port configuration bits 12.4 ports as general digital i/o the ports are bi-directional i/o ports with optional internal pull-ups. figure 12-4 shows a func- tional description of one i/o-port pin, here generically called pxn. note note 1. when switching a low level, ledcr device has a permanent current of about n ma/15 (n is 2 or 4) 2. the port must be configured and driven as standard io port. table 12-1. led configuration ledx.1 ledx.0 port latch data nmos pin comments 00 0 10 led control disabled (1) 00 1 01 01 0 00 led mode 2 ma 01 1 01 10 0 00 led mode 4 ma 10 1 01 bit 76543 2 1 0 $000075 led3 [1..0] led2 [1..0] led1 [1..0] led0 [1..0] ledcr read/writerrrrr r r r initial value00000 0 0 00x00 table 12-1 . led port selection ledn1 ledn0 description 0 0 led control disabled 0 1 2 ma current source 1 0 4 ma current source 1 1 reserved configuration note note for implementation example, please see section ?typical application? on page 414 .
at90scr100/116/132 86 tpr0327b ? vic ? 16fev11 figure 12-4. general digital i/o 12.4.1 configuring the pin each port pin consists of three register bits: ddxn, portxn, and pinxn. as shown in ?register description for i/o-ports? on page 91 , the ddxn bits are accessed at the ddrx i/o address, the portxn bits at the portx i/o address, and the pinxn bits at the pinx i/o address. the ddxn bit in the ddrx register selects the direction of this pin. if ddxn is written logic one, pxn is configured as an output pin. if ddxn is written logic zero, pxn is configured as an input pin. note note wrx, wpx, wdx, rrx, rpx, and rdx are common to all pins within the same port. clk i/o , sleep, and pud are common to all ports. clk rpx rrx rdx wdx pud synchronizer wdx: write ddrx wrx: write portx rrx: read portx register rpx: read portx pin pud: pullup disable clk i/o : i/o clock rdx: read ddrx d l q q reset reset q q d q q d clr portxn q q d clr ddxn pinxn data bus sleep sleep: sleep control pxn i/o wpx 0 1 wrx wpx: write pinx register
87 tpr0327b ? vic ? 16fev11 12. i/o ports at90scr100/116/132 if portxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated. to switch the pull-up resistor off, port xn has to be written logic zero or the pin has to be configured as an output pin. the port pins are tri-stated when the reset condition becomes active, even if no clocks are running. if portxn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). if portxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). 12.4.2 toggling the pin writing a logic one to pinxn toggles the value of portxn, independent on the value of ddrxn. note that the sbi instruction can be used to toggle one single bit in a port. 12.4.3 switching between input and output when switching between tri-state ({ddxn, portxn} = 0b00) and output high ({ddxn, portxn} = 0b11), an intermediate state with either pull-up enabled {ddxn, portxn} = 0b01) or output low ({ddxn, portxn} = 0b10) must occur. normally, the pull-up enabled state is fully accept- able, as a high-impedant environment will not notice the difference between a strong high driver and a pull-up. if this is not the case, the pud bit in the mcucr register can be set to disable all pull-ups in all ports. switching between input with pull-up and output low generates the same problem. the user must use either the tri-state ({ddxn, portxn} = 0b00) or the output high state ({ddxn, portxn} = 0b11) as an intermediate step. table 12-2 summarizes the control signals for the pin value. 12.4.4 reading the pin value independent of the setting of data direction bit ddxn, the port pin can be read through the pinxn register bit. as shown in figure 12-4 , the pinxn register bit and the preceding latch con- stitute a synchronizer. this is needed to avoid metastability if the physical pin changes value near the edge of the internal clock, but it also introduces a delay. figure 12-5 shows a timing dia- gram of the synchronization when reading an ex ternally applied pin value. the maximum and minimum propagation delays are denoted t pd,max and t pd,min respectively. table 12-2. port pin configurations ddxn portxn pud (in mcucr) i/o pull-up comment 0 0 x input no tri-state (hi-z) 0 1 0 input yes pxn will source current if ext. pulled low. 0 1 1 input no tri-state (hi-z) 1 0 x output no output low (sink) 1 1 x output no output high (source)
at90scr100/116/132 88 tpr0327b ? vic ? 16fev11 figure 12-5. synchronization when reading an externally applied pin value consider the clock period starting shortly after the first falling edge of the system clock. the latch is closed when the clock is low, and goes transparent when the clock is high, as indicated by the shaded region of the ?sync latch? signal. the signal value is latched when the system clock goes low. it is clocked into the pinxn register at the succeeding positive clock edge. as indi- cated by the two arrows tpd,max and tpd,min, a single signal transition on the pin will be delayed between ? and 1? system clock period depending upon the time of assertion. when reading back a software assigned pin value, a nop instruction must be inserted as indi- cated in figure 12-6 . the out instruction sets the ?sync latch? signal at the positive edge of the clock. in this case, the delay tpd through the synchronizer is 1 system clock period. figure 12-6. synchronization when reading a software assigned pin value the following code example shows how to set port b pins 0 and 1 high, 2 and 3 low, and define the port pins from 4 to 7 as input with pull-ups assigned to port pins 6 and 7. the resulting pin xxx in r17, pinx 0x00 0xff instructions sync latch pinxn r17 xxx system clk t pd, max t pd, min out portx, r16 nop in r17, pinx 0xff 0x00 0xff system clk r16 instructions sync latch pinxn r17 t pd
89 tpr0327b ? vic ? 16fev11 12. i/o ports at90scr100/116/132 values are read back again, but as previously discussed, a nop instruction is included to be able to read back the value recently assigned to some of the pins. note: 1. for the assembly program, two temporary registers are used to minimize the time from pull- ups are set on pins 0, 1, 6, and 7, until the direction bits are correctly set, defining bit 2 and 3 as low and redefining bits 0 and 1 as strong high drivers. 12.4.5 digital input enable and sleep modes as shown in figure 12-4 , the digital input signal can be clamped to ground at the input of the schmitt-trigger. the signal denoted sleep in the figure, is set by the mcu sleep controller in power-down mode, power-save mode, standby and extended stand-by mode to avoid high power consumption if some input signals are left floating, or have an analog signal level close to v cc /2. sleep is overridden for port pins enabled as exte rnal interrupt pins. if the external interrupt request is not enabled, sleep is active also for these pins. if a logic high level (?one?) is present on an as ynchronous external interrupt pin configured as ?interrupt on rising edge, falling edge, or any logic change on pin? while the external interrupt is not enabled, the corresponding external interrupt flag will be set when resuming from the above mentioned sleep mode, as the clamping in these sleep mode produces the requested logic change. assembly code example (1) ... ; define pull-ups and set outputs high ; define directions for port pins ldi r16,(1< at90scr100/116/132 90 tpr0327b ? vic ? 16fev11 12.4.6 unconnected pins if some pins are unused, it is recommended to ensure that these pins have a defined level. even though most of the digital inputs are disabled in the deep sleep modes as described above, float- ing inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (reset, active mode and idle mode). the simplest method to ensure a defined level of an unused pin, is to enable the internal pull-up. in this case, the pull-up will be disabled duri ng reset. if low power consumption during reset is important, it is recommended to use an external pull-up or pull-down. connecting unused pins directly to v cc or gnd is not recommended, since this may cause excessive currents if the pin is accidentally configured as an output. 12.4.7 mcucr ? mcu control register ? bit 4 ? pud: pull-up disable when this bit is written to one, the pull-ups in the i/o ports are disabled even if the ddxn and portxn registers are configured to enable the pull-ups ({ddxn, portxn} = 0b01). see ?con- figuring the pin? on page 86 for more details about this feature. bit 76543 2 1 0 0x35 (0x55) jtd - -pud - - ivsel ivce mcucr read/write r/w r r r/w r r r/w r/w initial value00000 0 0 00x00
91 tpr0327b ? vic ? 16fev11 12. i/o ports at90scr100/116/132 12.5 register description for i/o-ports 12.5.1 porta ? port a data register 12.5.2 ddra ? port a data direction register 12.5.3 pina ? port a input pins address 12.5.4 portb ? port b data register 12.5.5 ddrb ? port b data direction register 12.5.6 pinb ? port b input pins address bit 76543 2 1 0 0x02 (0x22) porta [7..0] porta read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x01 (0x21) dda [7..0] ddra read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x00 (0x20) pina [7..0] pina read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value n/a n/a n/a n/a n/a n/a n/a n/a bit 76543 2 1 0 0x05 (0x25) portb [7..0] portb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x04 (0x24) ddb [7..0] ddrb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x03 (0x23) pinb [7..0] pinb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value n/a n/a n/a n/a n/a n/a n/a n/a
at90scr100/116/132 92 tpr0327b ? vic ? 16fev11 12.5.7 portc ? port c data register 12.5.8 ddrc ? port c data direction register 12.5.9 pinc ? port c input pins address 12.5.10 portd ? port d data register 12.5.11 ddrd ? port d data direction register 12.5.12 pind ? port d input pins address 12.5.13 porte ? port e data register bit 76543 2 1 0 0x08 (0x28) - - portc [5..0] portc read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x07 (0x27) - - ddc [5..0] ddrc read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x06 (0x26) - - pinc [5..0] pinc read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value n/a n/a n/a n/a n/a n/a n/a n/a bit 76543 2 1 0 0x0b (0x2b) portd [7..0] portd read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x0a (0x2a) ddd [7..0] ddrd read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x09 (0x29) pind [7..0] pind read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value n/a n/a n/a n/a n/a n/a n/a n/a bit 76543 2 1 0 0x0e (0x2e) porte [7..0] porte read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00
93 tpr0327b ? vic ? 16fev11 12. i/o ports at90scr100/116/132 12.5.14 ddre ? port e data direction register 12.5.15 pine ? port e input pins address ? bit 76543 2 1 0 0x0d (0x2d) dde [7..0] ddre read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000 0 0 00x00 bit 76543 2 1 0 0x0c (0x2c) pine [7..0] pine read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value n/a n/a n/a n/a n/a n/a n/a n/a
at90scr100/116/132 94 tpr0327b ? vic ? 16fev11
95 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13. timers this section contains the detailed description of all 3 timers embedded in the at90scr100/116/132. finally, a global chapter describes the mechanism for prescaler reset used on all 3 registers. 13.1 8-bit timer/counter0 with pwm timer/counter0 is a general purpose 8-bit timer/counter module, with two independent output compare units, and with pwm support. it allows accurate program execution timing (event man- agement) and wave generation. the main features are: ? two independent output compare units ? double buffered output compare registers ? clear timer on compare match (auto reload) ? glitch free, phase correct pulse width modulator (pwm) ? variable pwm period ? frequency generator ? three independent interrupt sources (tov0, ocf0a, and ocf0b) 13.1.1 overview a simplified block diagram of the 8-bit timer/counter0 is shown in figure 13-1 . for the actual placement of i/o pins, refer to ?pin list configuration? on page 15 . the device-specific i/o reg- ister and bit locations are listed in the ? ?8-bit timer/counter0 register description? on page 106 ?.
at90scr100/116/132 96 tpr0327b ? vic ? 16fev11 figure 13-1. 8-bit timer/counter0 block diagram 13.1.1.1 registers the timer/counter (tcnt0) and output compare registers (ocr0a and ocr0b) are 8-bit registers. interrupt request (abbreviated to int.req. in the figure) signals are all visible in the timer interrupt flag register (tifr0). all interrupts are individually masked with the timer inter- rupt mask register (timsk0). tifr0 and timsk0 are not shown in the figure. the timer/counter can be clocked internally, via the prescaler, or by an external clock source on the t0 pin. the clock select logic block controls which clock source and edge the timer/counter uses to increment (or decrement) its value. the timer/counter is inactive when no clock source is selected. the output from the clock select logic is referred to as the timer clock (clk t0 ). the double buffered output compare registers (ocr0a and ocr0b) are compared with the timer/counter value at all times. the result of the compare can be used by the waveform gen- erator to generate a pwm or variable frequency output on the output compare pins (oc0a and oc0b). see ?output compare unit? on page 98. for details. the compare match event will also set the compare flag (ocf0a or ocf0b) which can be used to generate an output compare interrupt request. 13.1.1.2 definitions many register and bit references in this section are written in general form. a a lower case ?x? replaces the output compare unit, in this case compare unit a or compare unit b. however, clock select timer/counter data bus ocr0a ocr0b = = tcnt0 waveform generation waveform generation oc0a oc0b = fixed top value control logic = 0 top bottom count clear direction tovn (int.req.) ocf0a (int.req.) ocf0b (int.req.) tccr0a tccr0b t0 edge detector ( from prescaler ) clk t0
97 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 when using the register or bit defines in a program, the precise form must be used, i.e., tcnt0 for accessing timer/counter0 counter value and so on. the definitions in table 13-1 are also used extensively throughout the document. 13.1.2 timer/counter clock sources the timer/counter can be clocked by an internal or an external clock source. the clock source is selected by the clock select logic which is controlled by the clock select (cs02:0) bits located in the timer/counter control register (tccr0b). for details on clock sources and pres- caler, see ?timer/counter prescaler? on page 162 . 13.1.3 counter unit the main part of the 8-bit timer/counter is the programmable bi-directional counter unit. figure 13-2 shows a block diagram of the counter and its surroundings. figure 13-2. counter unit block diagram signal description (internal signals): count increment or decrement tcnt0 by 1. direction select between increment and decrement. clear clear tcnt0 (set all bits to zero). clk t n timer/counter clock, referred to as clk t0 in the following. top signifies that tcnt0 has reached maximum value. bottom signifies that tcnt0 has reached minimum value (zero). depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clk t0 ). clk t0 can be generated from an external or internal clock source, selected by the clock select bits (cs02:0). when no clock source is selected (cs02:0 = 0) the timer is stopped. however, the tcnt0 value can be accessed by the cpu, regardless of whether clk t0 is present or not. a cpu write override s (has priority over) all counter clear or count operations. table 13-1. definitions bottom the counter reaches the bottom when it becomes 0x00. max the counter reaches its maximum when it becomes 0xff (decimal 255). top the counter reaches the top when it becomes equal to the highest value in the count sequence. the top value can be assigned to be the fixed value 0xff (max) or the value stored in the ocr0a register. the assignment is depen- dent on the mode of operation. data bus tcnt0 control logic count tov0 (int.req.) clock select top t0 edge detector ( from prescaler ) clk tn bottom direction clear
at90scr100/116/132 98 tpr0327b ? vic ? 16fev11 the counting sequence is determined by the setting of the wgm01 and wgm00 bits located in the timer/counter control register (tccr0a) and the wgm02 bit located in the timer/counter control register b (tccr0b). there are close connections between how the counter behaves (counts) and how waveforms are generated on the output compare outputs oc0a and oc0b. for more details about advanced counting sequences and waveform generation, see ?modes of operation? on page 100 . the timer/counter overflow flag (tov0) is set according to the mode of operation selected by the wgm02:0 bits. tov0 can be used for generating a cpu interrupt. 13.1.4 output compare unit the 8-bit comparator continuously compares tcnt0 with the output compare registers (ocr0a and ocr0b). whenever tcnt0 equals ocr0a or ocr0b, the comparator signals a match. a match will set the output compare flag (ocf0a or ocf0b) at the next timer clock cycle. if the corresponding interrupt is enabled, the output compare flag generates an output compare interrupt. the output compare flag is automatically cleared when the interrupt is exe- cuted. alternatively, the flag can be cleared by software by writing a logical one to its i/o bit location. the waveform generator uses the match signal to generate an output according to operating mode set by the wgm02:0 bits and compare output mode (com0x1:0) bits. the top and bottom signals are used by the waveform generator for handling the special cases that occur in some modes of operation when maximum and minimum values are reached ( ?modes of operation? on page 100 ). figure 13-3 shows a block diagram of the output compare unit. figure 13-3. output compare unit, block diagram the ocr0x registers are double buffered when using any of the pulse width modulation (pwm) modes. for the normal and clear timer on compare (ctc) modes of operation, the dou- ble buffering is disabled. the double buffering synchronizes the update of the ocr0x compare registers to either the top or bottom of the counting sequence. the synchronization prevents the occurrence of odd-length, non-symmetrical pwm pulses, thereby making the output glitch-free. ocf0 x (int.req.) = (8-bit comparator ) ocr0x oc0x data bus tcnt0 wgm02:0 waveform generator top foc0x com0x1:0 bottom
99 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 the ocr0x register access may seem complex, but this is not case. when the double buffering is enabled, the cpu has access to the ocr0x buffer register, and if double buffering is dis- abled the cpu will access the ocr0x directly. 13.1.4.1 force output compare in non-pwm waveform generation modes, the match output of the comparator can be forced by writing a one to the force output compare (foc0x) bit. forcing compare match will not set the ocf0x flag or reload/clear the timer, but the oc0x pin will be updated as if a real compare match had occurred (the com0x1:0 bits settings define whether the oc0x pin is set, cleared or toggled). 13.1.4.2 compare match blocking by tcnt0 write all cpu write operations to the tcnt0 register will block any compare match that occur in the next timer clock cycle, even when the timer is stopped. this feature allows ocr0x to be initial- ized to the same value as tcnt0 without triggering an interrupt when the timer/counter clock is enabled. 13.1.4.3 using the output compare unit since writing tcnt0 in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing tcnt0 when using the output compare unit, independently of whether the timer/counter is running or not. if the value written to tcnt0 equals the ocr0x value, the compare match will be missed, resulting in incorrect waveform generation. similarly, do not write the tcnt0 value equal to bottom when the counter is down-counting. the setup of the oc0x should be performed before setting the data direction register for the port pin to output. the easiest way of setting the oc0x value is to use the force output com- pare (foc0x) strobe bits in normal mode. the oc0x registers keep their values even when changing between waveform generation modes. changing the com0x1:0 bits will take effect immediately. 13.1.5 compare match output unit the compare output mode (com0x1:0) bits have two functions. the waveform generator uses the com0x1:0 bits for defining the output compare (oc0x) state at the next compare match. also, the com0x1:0 bits control the oc0x pin output source. figure 13-4 shows a simplified schematic of the logic affected by the com0x1:0 bit setting. the i/o registers, i/o bits, and i/o pins in the figure are shown in bold. only the parts of the general i/o port control registers (ddr and port) that are affected by the com0x1:0 bits are shown. when referring to the oc0x state, the reference is for the internal oc0x register, not the oc0x pin. if a system reset occurs, the oc0x register is reset to ?0?.
at90scr100/116/132 100 tpr0327b ? vic ? 16fev11 figure 13-4. compare match output unit, schematic the general i/o port function is overridden by the output compare (oc0x) from the waveform generator if either of the com0x1:0 bits are set. however, the oc0x pin direction (input or out- put) is still controlled by the data direction register (ddr) for the port pin. the data direction register bit for the oc0x pin (ddr_oc0x) must be set as an output before the oc0x value is visible on the pin. the port override function is independent of the waveform generation mode. the design of the output compare pin logic allows the initialization of the oc0x state before the output is enabled. note that some com0x1:0 bit settings are reserved for certain modes of oper- ation. see ?8-bit timer/counter0 register description? on page 106. 13.1.6 compare output mode and waveform generation the waveform generator uses the com0x1:0 bits differently in normal, ctc, and pwm modes. for all modes, setting the com0x1:0 = 0 instructs the waveform generator that no action on the oc0x register is to be performed on the next compare match. for compare output actions in the non-pwm modes refer to table 13-2 on page 107 . for fast pwm mode, refer to table 13-3 on page 107 , and for phase correct pwm refer to table 13-4 on page 107 . a change of the com0x1:0 bits state will have an effect at the first compare match after the bits are written. for non-pwm modes, the action can be forced to have an immediate effect by using the foc0x strobe bits. 13.1.7 modes of operation the mode of operation, i.e., the behavior of the timer/counter and the output compare pins, is defined by the combination of the waveform generation mode (wgm02:0) and the compare output mode (com0x1:0) bits. the compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. the com0x1:0 bits control whether the pwm output generated should be inverted or not (inverted or non-inverted pwm). for non- pwm modes the com0x1:0 bits control whether the output should be set, cleared, or toggled at a compare match ( see ?compare match output unit? on page 99. ). for detailed timing information see ?timer/counter timing diagrams? on page 105 . port ddr dq dq oc0x pin oc0x dq waveform generator com0x1 com0x0 0 1 data bus foc0n clk i/o
101 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.1.7.1 normal mode the simplest mode of operation is the normal mode (wgm02:0 = 0). in this mode the counting direction is always up (incrementing), and no counter clear is performed. the counter simply overruns when it passes its maximum 8-bit value (top = 0xff) and then restarts from the bot- tom (0x00). in normal operation the timer/counter overflow flag (tov0) will be set in the same timer clock cycle as the tcnt0 becomes zero. the tov0 flag in this case behaves like a ninth bit, except that it is only set, not cleared. howe ver, combined with the timer overflow interrupt that automatically clears the tov0 flag, the timer resolution can be increased by software. there are no special cases to consider in the normal mode, a new counter value can be written anytime. the output compare unit can be used to generate interrupts at some given time. using the out- put compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the cpu time. 13.1.7.2 clear timer on compare match (ctc) mode in clear timer on compare or ctc mode (wgm02:0 = 2), the ocr0a register is used to manipulate the counter resolution. in ctc mode the counter is cleared to zero when the counter value (tcnt0) matches the ocr0a. the ocr0a defines the top value for the counter, hence also its resolution. this mode allows greater control of the compare match output frequency. it also simplifies the operation of counting external events. the timing diagram for the ctc mode is shown in figure 13-5 . the counter value (tcnt0) increases until a compare match occurs between tcnt0 and ocr0a, and then counter (tcnt0) is cleared. figure 13-5. ctc mode, timing diagram an interrupt can be generated each time the counter value reaches the top value by using the ocf0a flag. if the interrupt is enabled, the interrupt handler routine can be used for updating the top value. however, changing top to a value close to bottom when the counter is run- ning with none or a low prescaler value must be done with care since the ctc mode does not have the double buffering feature. if the new value written to ocr0a is lower than the current value of tcnt0, the counter will miss the compare match. the counter will then have to count to its maximum value (0xff) and wrap around starting at 0x00 before the compare match can occur. for generating a waveform output in ctc mode, the oc0a output can be set to toggle its logical level on each compare match by setting the compare output mode bits to toggle mode (com0a1:0 = 1). the oc0a value will not be visible on the port pin unless the data direction for the pin is set to output. the waveform generated will have a maximum frequency of f oc0 = tcnt0 oc0x (toggle) oc0x interrupt flag set 1 4 period 2 3 (com0x1:0 = 1)
at90scr100/116/132 102 tpr0327b ? vic ? 16fev11 f clk_i/o /2 when ocr0a is set to zero (0x00). the waveform frequency is defined by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). as for the normal mode of operation, the tov0 flag is set in the same timer clock cycle that the counter counts from max to 0x00. 13.1.7.3 fast pwm mode the fast pulse width modulation or fast pwm mode (wgm02:0 = 3 or 7) provides a high fre- quency pwm waveform generation option. the fast pwm differs from the other pwm option by its single-slope operation. the counter counts from bottom to top then restarts from bot- tom. top is defined as 0xff when wgm2:0 = 3, and ocr0a when wgm2:0 = 7. in non- inverting compare output mode, the output compare (oc0x) is cleared on the compare match between tcnt0 and ocr0x, and set at bottom. in inverting compare output mode, the out- put is set on compare match and cleared at bottom. due to the single-slope operation, the operating frequency of the fast pwm mode can be twice as high as the phase correct pwm mode that use dual-slope operation. this high frequency makes the fast pwm mode well suited for power regulation, rectification, and dac applications. high frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost. in fast pwm mode, the counter is incremented until the counter value matches the top value. the counter is then cleared at the following timer clock cycle. the timing diagram for the fast pwm mode is shown in figure 13-6 . the tcnt0 value is in the timing diagram shown as a his- togram for illustrating the single-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt0 slopes represent com- pare matches between ocr0x and tcnt0. figure 13-6. fast pwm mode, timing diagram the timer/counter overflow flag (tov0) is set each time the counter reaches top. if the inter- rupt is enabled, the interrupt handler routine can be used for updating the compare value. f ocnx f clk_i/o 2 n 1 ocrnx + () ?? ------------------------------------------------- - = tcnt0 ocr0x update and tov0 interrupt flag set 1 period 2 3 oc0x oc0x (com0x1:0 = 2) (com0x1:0 = 3) ocr0x interrupt flag set 4 5 6 7
103 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 in fast pwm mode, the compare unit allows generation of pwm waveforms on the oc0x pins. setting the com0x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com0x1:0 to three: setting the com0a1:0 bits to one allows the oc0a pin to toggle on compare matches if the wgm02 bit is set. this option is not available for the oc0b pin (see table 13-3 on page 107 ). the actual oc0x value will only be visible on the port pin if the data direction for the port pin is set as output. the pwm waveform is gener- ated by setting (or clearing) the oc0x regi ster at the compare match between ocr0x and tcnt0, and clearing (or setting) the oc0x register at the timer clock cycle the counter is cleared (changes from top to bottom). the pwm frequency for the output can be calculated by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). the extreme values for the ocr0a register represents special cases when generating a pwm waveform output in the fast pwm mode. if the ocr0a is set equal to bottom, the output will be a narrow spike for each max+1 timer clock cycle. setting the ocr0a equal to max will result in a constantly high or low output (depending on the polarity of the output set by the com0a1:0 bits.) a frequency (with 50% duty cycle) waveform output in fast pwm mode can be achieved by set- ting oc0x to toggle its logical level on each compare match (com0x1:0 = 1). the waveform generated will have a maximum frequency of f oc0 = f clk_i/o /2 when ocr0a is set to zero. this feature is similar to the oc0a toggle in ctc mode, except the double buffer feature of the out- put compare unit is enabled in the fast pwm mode. 13.1.7.4 phase correct pwm mode the phase correct pwm mode (wgm02:0 = 1 or 5) provides a high resolution phase correct pwm waveform generation option. the phase correct pwm mode is based on a dual-slope operation. the counter counts repeatedly from bottom to top and then from top to bot- tom. top is defined as 0xff when wgm2:0 = 1, and ocr0a when wgm2:0 = 5. in non- inverting compare output mode, the output compare (oc0x) is cleared on the compare match between tcnt0 and ocr0x while upcounting, and set on the compare match while down- counting. in inverting output compare mode, the operation is inverted. the dual-slope operation has lower maximum operation frequency than single slope operation. however, due to the sym- metric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. in phase correct pwm mode the counter is incremented until the counter value matches top. when the counter reaches top, it changes the count direction. the tcnt0 value will be equal to top for one timer clock cycle. the timing diagram for the phase correct pwm mode is shown on figure 13-7 . the tcnt0 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt0 slopes represent compare matches between ocr0x and tcnt0. f ocnxpwm f clk_i/o n 256 ? ------------------ =
at90scr100/116/132 104 tpr0327b ? vic ? 16fev11 figure 13-7. phase correct pwm mode, timing diagram the timer/counter overflow flag (tov0) is set each time the counter reaches bottom. the interrupt flag can be used to generate an interrupt each time the counter reaches the bottom value. in phase correct pwm mode, the compare unit allows generation of pwm waveforms on the oc0x pins. setting the com0x1:0 bits to two will produce a non-inverted pwm. an inverted pwm output can be generated by setting the com0x1 :0 to three: setting the com0a0 bits to one allows the oc0a pin to toggle on compare matches if the wgm02 bit is set. this option is not available for the oc0b pin (see table 13-4 on page 107 ). the actual oc0x value will only be visible on the port pin if the data direction fo r the port pin is set as output. the pwm wave- form is generated by clearing (or setting) the oc0x register at the compare match between ocr0x and tcnt0 when the counter increments, and setting (or clearing) the oc0x register at compare match between ocr0x and tcnt0 when the counter decrements. the pwm fre- quency for the output when using phase correct pwm can be calculated by the following equation: the n variable represents the prescale factor (1, 8, 64, 256, or 1024). the extreme values for the ocr0a register represent special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr0a is set equal to bottom, the output will be continuously low and if set equal to max the output will be continuously high for non-inverted pwm mode. for inverted pwm the output will have the opposite logic values. at the very start of period 2 in figure 13-7 oc0x has a transition from high to low even though there is no compare match. the point of this transition is to guarantee symmetry around bot- tom. there are two cases that give a transition without compare match. ? ocr0a changes its value from max, like in figure 13-7 . when the ocr0a value is max the oc0 pin value is the same as the result of a down-counting compare match. to ensure tov0 interrupt flag set oc0x interrupt flag set 1 2 3 tcnt0 period oc0x oc0x (com0x1:0 = 2) (com0x1:0 = 3) ocr0x update f ocnxpcpwm f clk_i/o n 510 ? ------------------ =
105 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 symmetry around bottom the oc0 value at max must correspond to the result of an up- counting compare match. ? the timer starts counting from a value higher than the one in ocr0a, and for that reason misses the compare match and hence the oc0 change that would have happened on the way up. 13.1.8 timer/counter timing diagrams the timer/counter is a synchronous design and the timer clock (clk t0 ) is therefore shown as a clock enable signal in the following figures. the figures include information on when interrupt flags are set. figure 13-8 contains timing data for basic timer/counter operation. the figure shows the count sequence close to the max value in all modes other than phase correct pwm mode. figure 13-8. timer/counter timing diagram, no prescaling figure 13-9 shows the same timing data, but with the prescaler enabled. figure 13-9. timer/counter timing diagram, with prescaler (f clk_i/o /8) figure 13-10 shows the setting of ocf0b in all modes and ocf0a in all modes except ctc mode and pwm mode, where ocr0a is top. clk tn (clk i/o /1) tov0 clk i/o tcnt0 max - 1 max bottom bottom + 1 tov0 tcnt0 max - 1 max bottom bottom + 1 clk i/o clk tn (clk i/o /8)
at90scr100/116/132 106 tpr0327b ? vic ? 16fev11 figure 13-10. timer/counter timing diagram, setting of ocf0x, with prescaler (f clk_i/o /8) figure 13-11 shows the setting of ocf0a and the clearing of tcnt0 in ctc mode and fast pwm mode where ocr0a is top. figure 13-11. timer/counter timing diagram, clear timer on compare match mode, with pres- caler (f clk_i/o /8) 13.1.9 8-bit timer/counter0 register description 13.1.9.1 tccr0a ? timer/counter control register a ? bits 7..6 ? com0a1..0: compare match output a mode these bits control the output compare pin (oc0a) behavior. if one or both of the com0a1:0 bits are set, the oc0a output overrides the normal port functionality of the i/o pin it is con- nected. however, note that the data direction register (ddr) bit corresponding to which the oc0a pin must be set in order to enable the output driver. ocf0x ocr0x tcnt0 ocr0x value ocr0x - 1 ocr0x ocr0x + 1 ocr0x + 2 clk i/o clk tn (clk i/o /8) ocf0x ocr0x tcnt0 (ctc) top top - 1 top bottom bottom + 1 clk i/o clk tn (clk i/o /8) bit 76543 2 10 0x24 (0x44) com0a1 com0a0 com0b1 com0b0 - - wgm01 wgm00 tccr0a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
107 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 when oc0a is connected to the pin, the function of the com0a1:0 bits depends on the wgm02:0 bit setting. table 13-2 shows the com0a1:0 bit functionality when the wgm02:0 bits are set to a normal or ctc mode (non-pwm). table 13-3 shows the com0a1:0 bit functionality when the wgm01:0 bits are set to fast pwm mode. note: 1. a special case occurs when ocr0a equals top and com0a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see ?fast pwm mode? on page 102 for more details. table 13-4 shows the com0a1:0 bit functionality when the wgm02:0 bits are set to phase cor- rect pwm mode. note: 1. a special case occurs when ocr0a equals top and com0a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see ?phase correct pwm mode? on page 103 for more details. ? bits 5..4 ? com0b1..0: compare match output b mode these bits control the output compare pin (oc0b) behavior. if one or both of the com0b1:0 bits are set, the oc0b output overrides the normal port functionality of the i/o pin to which it is table 13-2. compare output mode, non-pwm mode com0a1 com0a0 description 0 0 normal port operation, oc0a disconnected. 0 1 toggle oc0a on compare match 1 0 clear oc0a on compare match 1 1 set oc0a on compare match table 13-3. compare output mode, fast pwm mode (1) com0a1 com0a0 description 0 0 normal port operation, oc0a disconnected. 01 wgm02 = 0: normal port operation, oc0a disconnected. wgm02 = 1: toggle oc0a on compare match. 10 clear oc0a on compare match, set oc0a at bottom (non-inverting mode) 11 set oc0a on compare match, clear oc0a at bottom (inverting mode) table 13-4. compare output mode, phase correct pwm mode (1) com0a1 com0a0 description 0 0 normal port operation, oc0a disconnected. 01 wgm02 = 0: normal port operation, oc0a disconnected. wgm02 = 1: toggle oc0a on compare match. 10 clear oc0a on compare match when up-counting. set oc0a on compare match when down-counting. 11 set oc0a on compare match when up-counting. clear oc0a on compare match when down-counting.
at90scr100/116/132 108 tpr0327b ? vic ? 16fev11 connected. however, note that the data direction register (ddr) bit corresponding to the oc0b pin must be set in order to enable the output driver. when oc0b is connected to the pin, the function of the com0b1:0 bits depends on the wgm02:0 bit setting. table 13-5 shows the com0b1:0 bit functionality when the wgm02:0 bits are set to a normal or ctc mode (non-pwm). table 13-6 shows the com0b1:0 bit functionality when the wgm02:0 bits are set to fast pwm mode. note: 1. a special case occurs when ocr0b equals top and com0b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see ?fast pwm mode? on page 102 for more details. table 13-7 shows the com0b1:0 bit functionality when the wgm02:0 bits are set to phase cor- rect pwm mode. note: 1. a special case occurs when ocr0b equals top and com0b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see ?phase correct pwm mode? on page 103 for more details. ? bits 3..2 ? res: reserved bits these bits are reserved bits in the at90scr100/116/132 and will always read as zero. table 13-5. compare output mode, non-pwm mode com0b1 com0b0 description 0 0 normal port operation, oc0b disconnected. 0 1 toggle oc0b on compare match 1 0 clear oc0b on compare match 1 1 set oc0b on compare match table 13-6. compare output mode, fast pwm mode (1) com0b1 com0b0 description 0 0 normal port operation, oc0b disconnected. 01reserved 10 clear oc0b on compare match, set oc0b at bottom (non-inverting mode) 11 set oc0b on compare match, clear oc0b at bottom (inverting mode) table 13-7. compare output mode, phase correct pwm mode (1) com0b1 com0b0 description 0 0 normal port operation, oc0b disconnected. 01reserved 10 clear oc0b on compare match when up-counting. set oc0b on compare match when down-counting. 11 set oc0b on compare match when up-counting. clear oc0b on compare match when down-counting.
109 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 ? bits 1..0 ? wgm01..0: waveform generation mode when combined with the wgm02 bit found in the tccr0b register, these bits control the counting sequence of the counter, the source for maximum (top) counter value, and what type of waveform generation to be used, see table 13-8 . modes of operation supported by the timer/counter unit are: normal mode (counter), clear timer on compare match (ctc) mode, and two types of pulse width modulation (pwm) modes (see ?modes of operation? on page 100 ). note: 1. max = 0xff, bottom = 0x00 13.1.9.2 tccr0b ? timer/counter control register b ? bit 7 ? foc0a: force output compare a the foc0a bit is only active when the wgm bits specify a non-pwm mode. however, for ensuring compatibility with future devices, this bit must be set to zero when tccr0b is written when operating in pwm mode . when writing a logical one to the foc0a bit, an immediate compare match is forced on the waveform generation unit. the oc0a output is changed according to its com0a1:0 bits setting. note that the foc0a bit is implemented as a strobe. therefore it is the value present in the com0a1:0 bits that determines the effect of the forced compare. a foc0a strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr0a as top. the foc0a bit is always read as zero. ? bit 6 ? foc0b: force output compare b the foc0b bit is only active when the wgm bits specify a non-pwm mode. table 13-8. waveform generation mode bit description mode wgm2 wgm1 wgm0 timer/counter mode of operation top update of ocrx at tov flag set on (1) 0 0 0 0 normal 0xff immediate max 1001 pwm, phase correct 0xff top bottom 2 0 1 0 ctc ocra immediate max 3 0 1 1 fast pwm 0xff top max 4100 reserved ? ? ? 5101 pwm, phase correct ocra top bottom 6110 reserved ? ? ? 7111 fast pwmocratop top bit 76543 2 10 0x25 (0x45) foc0a foc0b - - wgm02 cs02 cs01 cso0 tccr0b read/write w w r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 110 tpr0327b ? vic ? 16fev11 however, for ensuring compatibility with future devices, this bit must be set to zero when tccr0b is written when operating in pwm mode. when writing a logical one to the foc0b bit, an immediate compare match is forced on the waveform generation unit. the oc0b output is changed according to its com0b1:0 bits setting. note that the foc0b bit is implemented as a strobe. therefore it is the value present in the com0b1:0 bits that determines the effect of the forced compare. a foc0b strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr0b as top. the foc0b bit is always read as zero. ? bits 5..4 ? res: reserved bits these bits are reserved bits and will always read as zero. ? bit 3 ? wgm02: waveform generation mode see the description in the ?tccr0a ? timer/counter control register a? on page 106 . ? bits 2..0 ? cs02..0: clock select the three clock select bits select the clock source to be used by the timer/counter. if external pin modes are used for the timer/counter0, transitions on the t0 pin will clock the counter even if the pin is configured as an output. this feature allows software control of the counting. 13.1.9.3 tcnt0 ? timer/counter register the timer/counter register gives direct access, both for read and write operations, to the timer/counter unit 8-bit counter. writing to the tcnt0 register blocks (removes) the compare match on the following timer clock. modifying the counter (tcnt0) while the counter is running, introduces a risk of missing a compare match between tcnt0 and the ocr0x registers. table 13-9. clock select bit description cs02 cs01 cs00 description 0 0 0 no clock source (timer/counter stopped) 001clk i/o /(no prescaling) 010clk i/o /8 (from prescaler) 011clk i/o /64 (from prescaler) 100clk i/o /256 (from prescaler) 101clk i/o /1024 (from prescaler) 1 1 0 external clock source on t0 pin. clock on falling edge. 1 1 1 external clock source on t0 pin. clock on rising edge. bit 76543 2 10 0x26 (0x46) tcnt0 [7..0] tcnt0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
111 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.1.9.4 ocr0a ? output compare register a the output compare register a contains an 8-bit value that is continuously compared with the counter value (tcnt0). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc0a pin. 13.1.9.5 ocr0b ? output compare register b the output compare register b contains an 8-bit value that is continuously compared with the counter value (tcnt0). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc0b pin. 13.1.9.6 timsk 0 ? timer/counter interrupt mask register ? bits 7..3 ? res: reserved bits these bits are reserved bits and will always read as zero. ? bit 2 ? ocie0b: timer/counter output compare match b interrupt enable when the ocie0b bit is written to one, and t he i-bit in the status register is set, the timer/counter compare match b interrupt is enabled. the corresponding interrupt is executed if a compare match in timer/counter occurs, i.e., when the ocf0b bit is set in the timer/counter interrupt flag register ? tifr0. ? bit 1 ? ocie0a: timer/counter0 output compare match a interrupt enable when the ocie0a bit is written to one, and t he i-bit in the status register is set, the timer/counter0 compare match a interrupt is enabled. the corresponding interrupt is executed if a compare match in timer/counter0 occurs, i.e., when the ocf0a bit is set in the timer/counter 0 interrupt flag register ? tifr0. ? bit 0 ? toie0: timer/counter0 overflow interrupt enable when the toie0 bit is written to one, and the i-bit in the status register is set, the timer/counter0 overflow interrupt is enabled. the corresponding interrupt is executed if an overflow in timer/counter0 occurs, i.e., when the tov0 bit is set in the timer/counter 0 inter- rupt flag register ? tifr0. bit 76543 2 10 0x27 (0x47) ocr0a [7..0] ocr0a read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 0x26 (0x46) ocr0b [7..0] ocr0b read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 0x6e -----ocie0bocie0atoie0timsk0 read/writerrrrrr/wr/wr/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 112 tpr0327b ? vic ? 16fev11 13.1.9.7 tifr 0 ? timer/counter 0 interrupt flag register ? bits 7..3 ? res : reserved bits these bits are reserved bits in the at90scr100/116/132 and will always read as zero. ? bit 2 ? ocf0b: timer/counter 0 output compare b match flag the ocf0b bit is set when a compare match occurs between the timer/counter and the data in ocr0b ? output compare register0 b. ocf0b is cleared by hardware when executing the cor- responding interrupt handling vector. alternatively, ocf0b is cleared by writing a logic one to the flag. when the i-bit in sreg, ocie0b (timer/counter compare b match interrupt enable), and ocf0b are set, the timer/counter compare match interrupt is executed. ? bit 1 ? ocf0a: timer/counter 0 output compare a match flag the ocf0a bit is set when a compare match occurs between the timer/counter0 and the data in ocr0a ? output compare register0. ocf0a is cleared by hardware when executing the cor- responding interrupt handling vector. alternatively, ocf0a is cleared by writing a logic one to the flag. when the i-bit in sreg, ocie0a (timer/counter0 compare match interrupt enable), and ocf0a are set, the timer/counter0 compare match interrupt is executed. ? bit 0 ? tov0: timer/counter0 overflow flag the bit tov0 is set when an overflow occurs in timer/counter0. tov0 is cleared by hardware when executing the corresponding interrupt handli ng vector. alternatively, tov0 is cleared by writing a logic one to the flag. when the sreg i-bit, toie0 (timer/counter0 overflow interrupt enable), and tov0 are set, the timer/counter0 overflow interrupt is executed. the setting of this flag is dependent of the wgm02:0 bit setting. refer to table 13-8, ?waveform generation mode bit description? on page 109 . bit 76543 2 10 0x15 (0x35) -----ocf0bocf0atov0tifr0 read/writerrrrrr/wr/wr/w initial value 0 0 0 0 0 0 0 0 0x00
113 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.2 16-bit timer/counter1 with pwm the 16-bit timer/counter unit allows accurate program execution timing (event management), wave generation, and signal timing measurement. the main features are: ? true 16-bit design (i.e., allows 16-bit pwm) ? two independent output compare units ? double buffered output compare registers ? one input capture unit ? input capture noise canceler ? clear timer on compare match (auto reload) ? glitch-free, phase correct pulse width modulator (pwm) ? variable pwm period ? frequency generator ? external event counter ? four independent interrupt sources (tov1, ocf1a, ocf1b, and icf1) 13.2.1 overview a simplified block diagram of the 16-bit timer/counter is shown in figure 13-12 . for the actual placement of i/o pins, refer to ?pin list configuration? on page 15 . cpu accessible i/o regis- ters, including i/o bits and i/o pins, are shown in bold. the device-specific i/o register and bit locations are listed in the ?16-bit timer/counter register description? on page 134 . the prtim1 bit in ?prr0 ? power reduction register 0? on page 54 must be written to zero to enable timer/counter1 module. refer to ?pin list configuration? on page 15 for timer/counter1 pin placement and description.
at90scr100/116/132 114 tpr0327b ? vic ? 16fev11 figure 13-12. 16-bit timer/counter block diagram 13.2.1.1 registers the timer/counter1 (tcnt1), output compare registers (ocr1a/b), and input capture reg- ister (icr1) are all 16-bit registers. special procedures must be followed when accessing the 16- bit registers. these procedures are described in the section ?accessing 16-bit registers? on page 115 . the timer/counter control registers (tccr1a/b/c) are 8-bit registers and have no cpu access restrictions. interrupt requests (abbreviated to int.req. in the figure) signals are all visible in the timer interrupt flag register (tifr1). all interrupts are individually masked with the timer interrupt mask register (timsk1). tifr1 and timsk1 are not shown in the figure. the timer/counter1 can be clocked internally, via the prescaler, or by an external clock source on the t1 pin. the clock select logic block controls which clock source and edge the timer/counter uses to increment (or decrement) its value. the timer/counter1 is inactive when no clock source is selected. the output from the clock select logic is referred to as the timer clock (clk t n ). the double buffered output compare registers (ocr1a/b) are compared with the timer/coun- ter value at all time. the result of the compare can be used by the waveform generator to clock select timer/counter data bus ocr1a ocr1b icr1 = = tcnt1 waveform generation waveform generation oc1a oc1b noise canceler icp1 = fixed top values edge detector control logic = 0 top bottom count clear direction tov1 (int.req.) ocf1a (int.req.) ocf1b (int.req.) icf1 (int.req.) tccr1a tccr1b t1 edge detector ( from prescaler ) clk tn
115 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 generate a pwm or variable frequency output on the output compare pin (ocr1a/b). see ?output compare units? on page 121. the compare match event will also set the compare match flag (ocf1a/b) which can be used to generate an output compare interrupt request. the input capture register can capture the timer/counter value at a given external (edge trig- gered) event on either the input capture pin (icp1). the input capture unit includes a digital filtering unit (noise canceler) for reducing the chance of capturing noise spikes. the top value, or maximum timer/counter value, can in some modes of operation be defined by either the ocr1a register, the icr1 register, or by a set of fixed values. when using ocr1a as top value in a pwm mode, the ocr1a register can not be used for generating a pwm output. however, the top value will in this case be double buffered allowing the top value to be changed in run time. if a fixed top value is required, the icr1 register can be used as an alternative, freeing the ocr1a to be used as pwm output. 13.2.1.2 definitions most register and bit references in this secti on are written in general form. a lower case ?x? replaces the output compare unit channel. the following definitions are used extensively throughout the section: 13.2.2 accessing 16-bit registers the tcnt1, ocr1a/b, and icr1 are 16-bit registers that can be accessed by the 8/16-bit risc cpu via the 8-bit data bus. the 16-bit register must be byte accessed using two read or write operations. each 16-bit timer has a single 8-bit register for temporary storage of the high byte of the 16-bit access. the same temporary register is shared between all 16-bit registers within each 16-bit timer. accessing the low byte tri ggers the 16-bit read or write operation. when the low byte of a 16-bit register is written by the cpu, the high byte stored in the temporary register, and the low byte written are both copied into the 16-bit register in the same clock cycle. when the low byte of a 16-bit register is read by the cpu, the high byte of the 16-bit register is copied into the temporary register in the same clock cycle as the low byte is read. not all 16-bit accesses uses the temporary register for the high byte. reading the ocr1a/b 16- bit registers does not involve using the temporary register. to do a 16-bit write, the high byte must be written before the low byte. for a 16-bit read, the low byte must be read before the high byte. the following code examples show how to access the 16-bit timer registers assuming that no interrupts updates the temporary register. the same principle can be used directly for accessing the ocr1a/b and icr1 registers. note that when using ?c?, the compiler handles the 16-bit access. table 13-10. definitions bottom the counter reaches the bottom when it becomes 0x0000. max the counter reaches its max imum when it becomes 0xffff (decimal 65535). top the counter reaches the top when it becomes equal to the highest value in the count sequence. the top value can be assigned to be one of the fixed values: 0x00ff, 0x01ff, or 0x03ff, or to the value stored in the ocr1a or icr1 register. the assignment is dependent of the mode of operation.
at90scr100/116/132 116 tpr0327b ? vic ? 16fev11 note: 1. the example code assumes that the part specific header file is included. for i/o registers located in extended i/o map, ?in?, ?out?, ?sbis?, ?sbic?, ?cbi?, and ?sbi? instructions must be replaced with instructions that allow access to extended i/o. typically ?lds? and ?sts? combined with ? sbrs?, ?sbrc?, ?sbr?, and ?cbr?. the assembly code example returns the tcnt1 value in the r17:r16 register pair. it is important to notice that accessing 16-bit registers are atomic operations. if an interrupt occurs between the two instructions accessing the 16-bit register, and the interrupt code updates the temporary register by accessing the same or any other of the 16-bit timer regis- ters, then the result of the access outside the interrupt will be corrupted. therefore, when both the main code and the interrupt code update the temporary register, the main code must disable the interrupts during the 16-bit access. the following code examples show how to do an atomic read of the tcnt1 register contents. reading any of the ocr1a/b or icr1 registers can be done by using the same principle assembly code examples (1) ... ; set tcnt1 to 0x01ff ldi r17,0x01 ldi r16,0xff out tcnt1h,r17 out tcnt1l,r16 ; read tcnt1 into r17:r16 in r16,tcnt1l in r17,tcnt1h ... c code examples (1) unsigned int i; ... /* set tcnt1 to 0x01ff */ tcnt1 = 0x1ff; /* read tcnt1 into i */ i = tcnt1; ...
117 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 . note: 1. the example code assumes that the part specific header file is included. for i/o registers located in extended i/o map, ?in?, ?out?, ?sbis?, ?sbic?, ?cbi?, and ?sbi? instructions must be replaced with instructions that allow access to extended i/o. typically ?lds? and ?sts? combined with ? sbrs?, ?sbrc?, ?sbr?, and ?cbr?. the assembly code example returns the tcnt1 value in the r17:r16 register pair. assembly code example (1) tim16_readtcnt1: ; save global interrupt flag in r18,sreg ; disable interrupts cli ; read tcnt1 into r17:r16 in r16,tcnt1l in r17,tcnt1h ; restore global interrupt flag out sreg,r18 ret c code example (1) unsigned int tim16_readtcnt1( void ) { unsigned char sreg; unsigned int i; /* save global interrupt flag */ sreg = sreg; /* disable interrupts */ _cli(); /* read tcnt1 into i */ i = tcnt1; /* restore global interrupt flag */ sreg = sreg; return i; }
at90scr100/116/132 118 tpr0327b ? vic ? 16fev11 the following code examples show how to do an atomic write of the tcnt1 register contents. writing any of the ocr1a/b or icr1 registers can be done by using the same principle. note: 1. the example code assumes that the part specific header file is included. for i/o registers located in extended i/o map, ?in?, ?out?, ?sbis?, ?sbic?, ?cbi?, and ?sbi? instructions must be replaced with instructions that allow access to extended i/o. typically ?lds? and ?sts? combined with ? sbrs?, ?sbrc?, ?sbr?, and ?cbr?. the assembly code example requires that the r17:r16 register pair contains the value to be writ- ten to tcnt1. 13.2.2.1 reusing the temporary high byte register if writing to more than one 16-bit register where the high byte is the same for all registers written, then the high byte only needs to be written once. however, note that the same rule of atomic operation described previously also applies in this case. 13.2.3 timer/counter clock sources the timer/counter can be clocked by an internal or an external clock source. the clock source is selected by the clock select logic which is controlled by the clock select (cs12:0) bits located in the timer/counter control register b (tccr1b). for details on clock sources and prescaler, see ?timer/counter prescaler? on page 162 . assembly code example (1) tim16_writetcnt1: ; save global interrupt flag in r18,sreg ; disable interrupts cli ; set tcnt1 to r17:r16 out tcnt1h,r17 out tcnt1l,r16 ; restore global interrupt flag out sreg,r18 ret c code example (1) void tim16_writetcnt1( unsigned int i ) { unsigned char sreg; unsigned int i; /* save global interrupt flag */ sreg = sreg; /* disable interrupts */ _cli(); /* set tcnt1 to i */ tcnt1 = i; /* restore global interrupt flag */ sreg = sreg; }
119 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.2.4 counter unit the main part of the 16-bit timer/counter is the programmable 16-bit bi-directional counter unit. figure 13-13 shows a block diagram of the counter and its surroundings. figure 13-13. counter unit block diagram signal description (internal signals): count increment or decrement tcnt1 by 1. direction select between increment and decrement. clear clear tcnt1 (set all bits to zero). clk t n timer/counter clock. top signifies that tcnt1 has reached maximum value. bottom signifies that tcnt1 has reached minimum value (zero). the 16-bit counter is mapped into two 8-bit i/o memory locations: counter high (tcnt1h) con- taining the upper eight bits of the counter, and counter low (tcnt1l) containing the lower eight bits. the tcnt1h register can only be indirectly accessed by the cpu. when the cpu does an access to the tcnt1h i/o location, the cpu accesses the high byte temporary register (temp). the temporary register is updated with the tcnt1h value when the tcnt1l is read, and tcnt1h is updated with the temporary register value when tcnt1l is written. this allows the cpu to read or write the entire 16-bit counter value within one clock cycle via the 8-bit data bus. it is important to notice that there are special cases of writing to the tcnt1 register when the counter is counting that will give unpredictable re sults. the special cases are described in the sections where they are of importance. depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clk t n ). the clk t n can be generated from an external or internal clock source, selected by the clock select bits (cs12:0). when no clock source is selected (cs12:0 = 0) the timer is stopped. however, the tcnt1 value can be accessed by the cpu, independent of whether clk t n is present or not. a cpu write overrides (has priority over) all counter clear or count operations. the counting sequence is determi ned by the setting of the waveform generation mode bits (wgm13:0) located in the timer/counter control registers a and b (tccr1a and tccr1b). there are close connections between how the counter behaves (counts) and how waveforms are generated on the output compare outputs oc1x. for more details about advanced counting sequences and waveform generation, see ?modes of operation? on page 125 . temp (8-bit) data bus (8-bit) tcnt1 (16-bit counter) tcnt1h (8-bit) tcnt1l (8-bit) control logic count clear direction tov1 (int.req.) clock select top bottom t1 edge detector ( from prescaler ) clk tn
at90scr100/116/132 120 tpr0327b ? vic ? 16fev11 the timer/counter overflow flag (tov1) is set according to the mode of operation selected by the wgm13:0 bits. tov1 can be used for generating a cpu interrupt. 13.2.5 input capture unit the timer/counter incorporates an input capture unit that can capture external events and give them a time-stamp indicating the time of occurrence. the external signal indicating an event, or multiple events, can be applied via the icp1 pin. the time-stamps can then be used to calculate frequency, duty-cycle, and other features of the signal applied. alternatively the time-stamps can be used for creating a log of the events. the input capture unit is illustrated by the block diagram shown in figure 13-14 . the elements of the block diagram that are not directly a part of the input capture unit are gray shaded. figure 13-14. input capture unit block diagram when a change of the logic level (an event) occurs on the input capture pin (icp1) and this change conforms to the setting of the edge detector, a capture will be triggered. when a capture is triggered, the 16-bit value of the counter (tcnt1) is written to the input capture register (icr1). the input capture flag (icf1) is set at the same system clock as the tcnt1 value is copied into icr1 register. if enabled (icie1 = 1), the input capture flag generates an input capture interrupt. the icf1 flag is automatically cleared when the interrupt is executed. alter- natively the icf1 flag can be cleared by software by writing a logical one to its i/o bit location. reading the 16-bit value in the input capture register (icr1) is done by first reading the low byte (icr1l) and then the high byte (icr1h). when the low byte is read the high byte is copied into the high byte temporary register (temp). when the cpu reads the icr1h i/o location it will access the temp register. the icr1 register can only be written when us ing a waveform generation mode that utilizes the icr1 register for defining the counter?s top value. in these cases the waveform genera- tion mode (wgm13:0) bits must be set before the top value can be written to the icr1 register. when writing the icr1 register the high byte must be written to the icr1h i/o location before the low byte is written to icr1l. icf1 (int.req.) write icr1 (16-bit register) icr1h (8-bit) noise canceler icp1 edge detector temp (8-bit) data bus (8-bit) icr1l (8-bit) tcnt1 (16-bit counter) tcnt1h (8-bit) tcnt1l (8-bit) icnc ices
121 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 for more information on how to access the 16-bit registers refer to ?accessing 16-bit registers? on page 115 . 13.2.5.1 input capture trigger source the main trigger source for the input capture unit is the input capture pin (icp1). the input capture pin (icp1) is sampled using the same technique as for the tn pin ( figure 13- 12 on page 114 ). the edge detector is also identical. however, when the noise canceler is enabled, additional logic is inserted before the edge detector, which increases the delay by four system clock cycles. an input capture can be triggered by software by controlling the port of the icp1 pin. 13.2.5.2 noise canceler the noise canceler improves noi se immunity by using a simple digital filtering scheme. the noise canceler input is monitored over four samples, and all four must be equal to change the output that in turn is used by the edge detector. the noise canceler is enabled by setting the input capture noise canceler (icncn) bit in timer/counter control register b (tccr1b). when enabled the noise canceler introduces addi- tional four system clock cycles of delay from a change applied to the input, to the update of the icr1 register. the noise canceler uses the syst em clock and is therefore not affected by the prescaler. 13.2.5.3 using the input capture unit the main challenge when using the input capture unit is to assign enough processor capacity for handling the incoming events. the time between two events is critical. if the processor has not read the captured value in the icr1 register before the next event occurs, the icr1 will be overwritten with a new value. in this case the result of the capture will be incorrect. when using the input capture interrupt, the icr1 register should be read as early in the inter- rupt handler routine as possible. even though th e input capture interrupt has relatively high priority, the maximum interrupt response time is dependent on the maximum number of clock cycles it takes to handle any of the other interrupt requests. using the input capture unit in any mode of operation when the top value (resolution) is actively changed during operation, is not recommended. measurement of an external signal?s duty cycle requires that the trigger edge is changed after each capture. changing the edge sensing must be done as early as possible after the icr1 register has been read. after a change of the edge, the input capture flag (icf1) must be cleared by software (writing a logical one to the i/o bit location). for measuring frequency only, the clearing of the icf1 flag is not required (if an interrupt handler is used). 13.2.6 output compare units the 16-bit comparator continuously compares tcnt1 with the output compare register (ocr1x). if tcnt equals ocr1x the compar ator signals a match. a match will set the output compare flag (ocf1x) at the next timer clock cycle. if enabled (ocie1x = 1), the output com- pare flag generates an output compare interrupt. the ocf1x flag is automatically cleared note note the input of the noise canceler and edge detector is always enabled unless the timer/counter is set in a waveform generation mode that uses icr1 to define top.
at90scr100/116/132 122 tpr0327b ? vic ? 16fev11 when the interrupt is executed. alternatively the ocf1x flag can be cleared by software by writ- ing a logical one to its i/o bit location. the waveform generator uses the match signal to generate an output according to operating mode set by the waveform generation mode (wgm13:0) bits and compare output mode (com1x1:0) bits. the top and bottom signals are used by the waveform generator for handling the special cases that occur in some modes of operation when maximum and minimum values are reached ( see ?modes of operation? on page 125. ) a special feature of output compare unit a allows it to define the timer/counter top value (i.e., counter resolution). in addition to the counter resolution, the top value defines the period time for waveforms generated by the waveform generator. figure 13-15 shows a block diagram of the output compare unit. the ?x? indicates output com- pare unit (a/b/c). the elements of the block diagram that are not directly a part of the output compare unit are gray shaded. figure 13-15. output compare unit, block diagram the ocr1x register is double buffered when using any of the twelve pulse width modulation (pwm) modes. for the normal and clear timer on compare (ctc) modes of operation, the double buffering is disabled. the double buffering synchronizes the update of the ocr1x com- pare register to either top or bottom of the counting sequence. the synchronization prevents the occurrence of odd-length, non-symmetrical pwm pulses, thereby making the out- put glitch-free. the ocr1x register access may seem complex, but this is not case. when the double buffering is enabled, the cpu has access to the ocr1x buffer register, and if double buffering is dis- abled the cpu will access the ocr1x directly. the content of the ocr1x (buffer or compare) register is only changed by a write operation (the timer/counter does not update this register automatically as the tcnt1 and icr1 register). therefore ocr1x is not read via the high byte temporary register (temp). however, it is a good practice to read the low byte first as when accessing other 16-bit registers. writing the ocr1x registers must be done via the temp reg- ocf1x (int.req.) = (16-bit comparator ) ocr1x buer (16-bit register) ocr1xh buf. (8-bit) oc1x temp (8-bit) data bus (8-bit) ocr1xl buf. (8-bit) tcnt1 (16-bit counter) tcnt1h (8-bit) tcnt1l (8-bit) com1x1:0 wgm13:0 ocr1x (16-bit register) ocr1xh (8-bit) ocr1xl (8-bit) waveform generator top bottom
123 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 ister since the compare of all 16 bits is done c ontinuously. the high byte (ocr1xh) has to be written first. when the high byte i/o location is wr itten by the cpu, the temp register will be updated by the value written. then when the low byte (ocr1xl) is written to the lower eight bits, the high byte will be copied into the upper 8-bits of either the ocr1x buffer or ocr1x compare register in the same system clock cycle. for more information of how to access the 16-bit registers refer to ?accessing 16-bit registers? on page 115 . 13.2.6.1 force output compare in non-pwm waveform generation modes, the match output of the comparator can be forced by writing a one to the force output compare (foc1x) bit. forcing compare match will not set the ocf1x flag or reload/clear the timer, but the oc1x pin will be updated as if a real compare match had occurred (the com11:0 bits settings define whether the oc1x pin is set, cleared or toggled). 13.2.6.2 compare match blocking by tcnt1 write all cpu writes to the tcnt1 register will block any compare match that occurs in the next timer clock cycle, even when the timer is stopped. this feature allows ocr1x to be initialized to the same value as tcnt1 without triggering an interrupt when the timer/counter clock is enabled. 13.2.6.3 using the output compare unit since writing tcnt1 in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing t cnt1 when using any of the output compare channels, independent of whether the timer/counter is running or not. if the value written to tcnt1 equals the ocr1x value, the compare match will be missed, resulting in incorrect wave- form generation. do not write the tcnt1 equal to top in pwm modes with variable top values. the compare match for the top will be ignored and the counter will continue to 0xffff. similarly, do not write the tcnt1 value equal to bottom when the counter is downcounting. the setup of the oc1x should be performed before setting the data direction register for the port pin to output. the easiest way of setting the oc1x value is to use the force output com- pare (foc1x) strobe bits in normal mode. the oc1x register keeps its value even when changing between waveform generation modes. changing the com1x1:0 bits will take effect immediately.
at90scr100/116/132 124 tpr0327b ? vic ? 16fev11 13.2.7 compare match output unit the compare output mode (com1x1:0) bits have two functions. the waveform generator uses the com1x1:0 bits for defining the output compare (oc1x) state at the next compare match. secondly the com1x1:0 bits control the oc1x pin output source. figure 13-16 shows a simpli- fied schematic of the logic affected by the com1x1:0 bit setting. the i/o registers, i/o bits, and i/o pins in the figure are shown in bold. only the parts of the general i/o port control registers (ddr and port) that are affected by the com1x1:0 bits are shown. when referring to the oc1x state, the reference is for the internal oc1x register, not the oc1x pin. if a system reset occur, the oc1x register is reset to ?0?. figure 13-16. compare match output unit, schematic the general i/o port function is overridden by the output compare (oc1x) from the waveform generator if either of the com1x1:0 bits are set. however, the oc1x pin direction (input or out- put) is still controlled by the data direction register (ddr) for the port pin. the data direction register bit for the oc1x pin (ddr_oc1x) must be set as output before the oc1x value is visi- ble on the pin. the port override function is generally independent of the waveform generation mode, but there are some exceptions. refer to table 13-11 , table 13-12 and table 13-13 for details. the design of the output compare pin logic allows initialization of the oc1x state before the out- put is enabled. note that some com1x1:0 bit settings are reserved for certain modes of operation. see ?16-bit timer/counter register description? on page 134. the com1x1:0 bits have no effect on the input capture unit. port ddr dq dq oc1x pin oc1x dq waveform generator com1x1 com1x0 0 1 data bus foc1x clk i/o
125 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.2.7.1 compare output mode and waveform generation the waveform generator uses the com1x1:0 bits differently in normal, ctc, and pwm modes. for all modes, setting the com1x1:0 = 0 tells the waveform generator that no action on the oc1x register is to be performed on the next compare match. for compare output actions in the non-pwm modes refer to table 13-11 on page 134 . for fast pwm mode refer to table 13-12 on page 135 , and for phase correct and phase and frequency correct pwm refer to table 13-13 on page 135 . a change of the com1x1:0 bits state will have effect at the first compare match after the bits are written. for non-pwm modes, the action can be fo rced to have immediate effect by using the foc1x strobe bits. 13.2.8 modes of operation the mode of operation, i.e., the behavior of the timer/counter and the output compare pins, is defined by the combination of the waveform generation mode (wgm13:0) and compare output mode (com1x1:0) bits. the compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. the com1x1:0 bits control whether the pwm out- put generated should be inverted or not (inverted or non-inverted pwm). for non-pwm modes the com1x1:0 bits control whether the output should be set, cleared or toggle at a compare match ( see ?compare match output unit? on page 124. ) for detailed timing information refer to ?timer/counter timing diagrams? on page 132 . 13.2.8.1 normal mode the simplest mode of operation is the normal mode (wgm13:0 = 0). in this mode the counting direction is always up (incrementing), and no counter clear is performed. the counter simply overruns when it passes its maximum 16-bit value (max = 0xffff) and then restarts from the bottom (0x0000). in normal operation the timer/counter overflow flag (tov1) will be set in the same timer clock cycle as the tcnt1 becomes zero. the tov1 flag in this case behaves like a 17th bit, except that it is only set, not cleared. however, combined with the timer overflow interrupt that automatically clears the tov1 flag, the timer resolution can be increased by soft- ware. there are no special cases to consider in the normal mode, a new counter value can be written anytime. the input capture unit is easy to use in normal mode. however, observe that the maximum interval between the external events must not exceed the resolution of the counter. if the interval between events are too long, the timer overflow interrupt or the prescaler must be used to extend the resolution for the capture unit. the output compare units can be used to generate interrupts at some given time. using the output compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the cpu time. 13.2.8.2 clear timer on compare match (ctc) mode in clear timer on compare or ctc mode (wgm13:0 = 4 or 12), the ocr1a or icr1 register are used to manipulate the counter resolution. in ctc mode the counter is cleared to zero when the counter value (tcnt1) matches either the ocr1a (wgm13:0 = 4) or the icr1 (wgm13:0 = 12). the ocr1a or icr1 define the top value for the counter, hence also its resolution. this mode allows greater control of the compare match output frequency. it also simplifies the opera- tion of counting external events.
at90scr100/116/132 126 tpr0327b ? vic ? 16fev11 the timing diagram for the ctc mode is shown in figure 13-17 . the counter value (tcnt1) increases until a compare match occurs with either ocr1a or icr1, and then counter (tcnt1) is cleared. figure 13-17. ctc mode, timing diagram an interrupt can be generated at each time the counter value reaches the top value by either using the ocf1a or icf1 flag according to the register used to define the top value. if the interrupt is enabled, the interrupt handler routine can be used for updating the top value. how- ever, changing the top to a value close to bottom when the counter is running with none or a low prescaler value must be done with care since the ctc mode does not have the double buff- ering feature. if the new value written to ocr1a or icr1 is lower than the current value of tcnt1, the counter will miss the compare match. the counter will then have to count to its max- imum value (0xffff) and wrap around starting at 0x0000 before the compare match can occur. in many cases this feature is not desirable. an alternative will then be to use the fast pwm mode using ocr1a for defining top (wgm13:0 = 15) since the ocr1a then will be double buffered. for generating a waveform output in ctc mode, the oc1a output can be set to toggle its logical level on each compare match by setting the compare output mode bits to toggle mode (com1a1:0 = 1). the oc1a value will not be visible on the port pin unless the data direction for the pin is set to output (ddr_oc1a = 1). the waveform generated will have a maximum fre- quency of f oc1a = f clk_i/o /2 when ocr1a is set to zero (0x0000). the waveform frequency is defined by the following equation: the n variable represents the prescaler factor (1, 8, 64, 256, or 1024). as for the normal mode of operation, the tov1 flag is set in the same timer clock cycle that the counter counts from max to 0x0000. 13.2.8.3 fast pwm mode the fast pulse width modulation or fast pwm mode (wgm13:0 = 5, 6, 7, 14, or 15) provides a high frequency pwm waveform generation option. the fast pwm differs from the other pwm options by its single-slope operation. the counter counts from bottom to top then restarts from bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x, and set at bottom. in inverting compare output mode output is set on compare match and cleared at bottom. due to the single-slope operation, the operating frequency of the fast pwm mode can be twice as high as the phase cor- rect and phase and frequency correct pwm modes that use dual-slope operation. this high tcnt1 oc1a (toggle) oc1a interrupt flag set or icf1 interrupt flag set (interrupt on top) 1 4 period 2 3 (com1a1:0 = 1) f ocna f clk_i/o 2 n 1 ocrna + () ?? -------------------------------------------------- - =
127 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 frequency makes the fast pwm mode well suited for power regulation, rectification, and dac applications. high frequency allows physically sm all sized external components (coils, capaci- tors), hence reduces total system cost. the pwm resolution for fast pwm can be fixed to 8-, 9-, or 10-bit, or defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and the max- imum resolution is 16-bit (icr1 or ocr1a set to max). the pwm resolution in bits can be calculated by using the following equation: in fast pwm mode the counter is incremented until the counter value matches either one of the fixed values 0x00ff, 0x01ff, or 0x03ff (wgm13:0 = 5, 6, or 7), the value in icr1 (wgm13:0 = 14), or the value in ocr1a (wgm13:0 = 15). the counter is then cleared at the following timer clock cycle. the timing diagram for the fast pwm mode is shown in figure 13-18 . the figure shows fast pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matches between ocr1x and tcnt1. the oc1x interrupt flag will be set when a compare match occurs. figure 13-18. fast pwm mode, timing diagram the timer/counter overflow flag (tov1) is set each time the counter reaches top. in addition the oc1a or icf1 flag is set at the same timer clock cycle as tov1 is set when either ocr1a or icr1 is used for defining the top value. if one of the interrupts are enabled, the interrupt han- dler routine can be used for updating the top and compare values. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will never occur between the tcnt1 and the ocr1x. note that when using fixed top values the unused bits are masked to zero when any of the ocr1x registers are written. the procedure for updating icr1 differs from updating ocr1a when used for defining the top value. the icr1 register is not double buffered. this means that if icr1 is changed to a low value when the counter is running with none or a low prescaler value, there is a risk that the new icr1 value written is lower than the current value of tcnt1. the result will then be that the r fpwm top 1 + () log 2 () log ---------------------------------- - = tcnt1 ocr1x/top update and tov1 interrupt flag set and oc1a interrupt flag set or icf1 interrupt flag set (interrupt on top) 1 7 period 2 3 4 5 6 8 oc1x oc1x (com1x1:0 = 2) (com1x1:0 = 3)
at90scr100/116/132 128 tpr0327b ? vic ? 16fev11 counter will miss the compare match at the top value. the counter will then have to count to the max value (0xffff) and wrap around starting at 0x0000 before the compare match can occur. the ocr1a register however, is double buffered. this feature allows the ocr1a i/o location to be written anytime. when the ocr1a i/o location is written the value written will be put into the ocr1a buffer register. the ocr1a compare register will then be updated with the value in the buffer register at the next timer clock cycle the tcnt1 matches top. the update is done at the same timer clock cycle as the tcnt1 is cleared and the tov1 flag is set. using the icr1 register for defining top works well when using fixed top values. by using icr1, the ocr1a register is free to be used for generating a pwm output on oc1a. however, if the base pwm frequency is actively changed (by changing the top value), using the ocr1a as top is clearly a better choice due to its double buffer feature. in fast pwm mode, the compare units allow generation of pwm waveforms on the oc1x pins. setting the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table on page 135 ). the actual oc1x value will only be visible on the port pin if the dat a direction for the port pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1, and clearing (or setting) the oc1x register at the timer clock cycle the counter is cleared (changes from top to bottom). the pwm frequency for the output can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represents special cases when generating a pwm waveform output in the fast pwm mode. if the ocr1x is set equal to bottom (0x0000) the out- put will be a narrow spike for each top+1 timer clock cycle. setting the ocr1x equal to top will result in a constant high or low output (depending on the polarity of the output set by the com1x1:0 bits.) a frequency (with 50% duty cycle) waveform output in fast pwm mode can be achieved by set- ting oc1a to toggle its logical level on each compare match (com1a1:0 = 1). this applies only if ocr1a is used to define the top value (wgm13:0 = 15). the waveform generated will have a maximum frequency of f oc1a = f clk_i/o /2 when ocr1a is set to zero (0x0000). this feature is similar to the oc1a toggle in ctc mode, except the double buffer feature of the output com- pare unit is enabled in the fast pwm mode. 13.2.8.4 phase correct pwm mode the phase correct pulse width modulation or phase correct pwm mode (wgm13:0 = 1, 2, 3, 10, or 11) provides a high resolution phase correct pwm waveform generation option. the phase correct pwm mode is, like the phase and frequency correct pwm mode, based on a dual- slope operation. the counter counts repeatedly from bottom (0x0000) to top and then from top to bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x while upcounting, and set on the compare match while downcounting. in inverting output compare mode, the operation is inverted. the dual-slope operation has lower maximum operation frequency than single slope operation. however, due to the symmetric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. f ocnxpwm f clk_i/o n 1 top + () ? ---------------------------------- - =
129 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 the pwm resolution for the phase correct pwm mode can be fixed to 8-, 9-, or 10-bit, or defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and the maximum resolution is 16-bit (icr1 or ocr1a set to max). the pwm resolu- tion in bits can be calculated by using the following equation: in phase correct pwm mode the counter is incremented until the counter value matches either one of the fixed values 0x00ff, 0x01ff, or 0x03ff (wgm13:0 = 1, 2, or 3), the value in icr1 (wgm13:0 = 10), or the value in ocr1a (wgm13:0 = 11). the counter has then reached the top and changes the count direction. the tcnt1 value will be equal to top for one timer clock cycle. the timing diagram for the phase correct pwm mode is shown on figure 13-19 . the fig- ure shows phase correct pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes represent compare matches between ocr1x and tcnt1. the oc1x inter- rupt flag will be set when a compare match occurs. figure 13-19. phase correct pwm mode, timing diagram the timer/counter overflow flag (tov1) is set each time the counter reaches bottom. when either ocr1a or icr1 is used for defining the top value, the oc1a or icf1 flag is set accord- ingly at the same timer clock cycle as the ocr1x registers are updated with the double buffer value (at top). the interrupt flags can be used to generate an interrupt each time the counter reaches the top or bottom value. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will never occur between the tcnt1 and the ocr1x. note that when using fixed top values, the unused bits are masked to zero when any of the ocr1x registers are written. as the third period shown in figure 13-19 illustrates, changing the top actively while the timer/counter is running in the phase correct mode can result in an unsymmetrical output. the reason for this can be found in the time of update of the ocr1x reg- r pcpwm top 1 + () log 2 () log ---------------------------------- - = ocr1x/top update and oc1a interrupt flag set or icf1 interrupt flag set (interrupt on top) 1 2 3 4 tov1 interrupt flag set (interrupt on bottom) tcnt1 period oc1x oc1x (com1x1:0 = 2) (com1x1:0 = 3)
at90scr100/116/132 130 tpr0327b ? vic ? 16fev11 ister. since the ocr1x update occurs at top, the pwm period starts and ends at top. this implies that the length of the falling slope is determined by the previous top value, while the length of the rising slope is determined by the new top value. when these two values differ the two slopes of the period will differ in length. the difference in length gives the unsymmetrical result on the output. it is recommended to use the phase and frequency correct mode instead of the phase correct mode when changing the top value while the timer/counter is running. when using a static top value there are practically no differences between the two modes of operation. in phase correct pwm mode, the compare units allow generation of pwm waveforms on the oc1x pins. setting the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table on page 135 ). the actual oc1x value will only be visible on the port pin if the data direction for the port pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x regis- ter at the compare match between ocr1x and tcnt1 when the counter increments, and clearing (or setting) the oc1x register at compare match between ocr1x and tcnt1 when the counter decrements. the pwm frequency for the output when using phase correct pwm can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represent special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr1x is set equal to bottom the output will be continuously low and if set equal to top the output will be continuously high for non-inverted pwm mode. for inverted pwm the output will have the opposite logic values. if ocr1a is used to define the top value (wgm13:0 = 11) and com1a1:0 = 1, the oc1a output will toggle with a 50% duty cycle. 13.2.8.5 phase and frequency correct pwm mode the phase and frequency correct pulse width modulation, or phase and frequency correct pwm mode (wgm13:0 = 8 or 9) provides a high resolution phase and frequency correct pwm wave- form generation option. the phase and frequency correct pwm mode is, like the phase correct pwm mode, based on a dual-slope operation. the counter counts repeatedly from bottom (0x0000) to top and then from top to bottom. in non-inverting compare output mode, the output compare (oc1x) is cleared on the compare match between tcnt1 and ocr1x while upcounting, and set on the compare match while downcounting. in inverting compare output mode, the operation is inverted. the dual-slope operation gives a lower maximum operation fre- quency compared to the single-slope operation. however, due to the symmetric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. the main difference between the phase correct, and the phase and frequency correct pwm mode is the time the ocr1x register is updated by the ocr1x buffer register, (see figure 13- 19 and figure 13-20 ). the pwm resolution for the phase and frequency correct pwm mode can be defined by either icr1 or ocr1a. the minimum resolution allowed is 2-bit (icr1 or ocr1a set to 0x0003), and f ocnxpcpwm f clk_i/o 2 ntop ?? --------------------------- - =
131 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 the maximum resolution is 16-bit (icr1 or ocr1a set to max). the pwm resolution in bits can be calculated using the following equation: in phase and frequency correct pwm mode the counter is incremented until the counter value matches either the value in icr1 (wgm13:0 = 8), or the value in ocr1a (wgm13:0 = 9). the counter has then reached the top and changes the count direction. the tcnt1 value will be equal to top for one timer clock cycle. the timing diagram for the phase correct and frequency correct pwm mode is shown on figure 13-20 . the figure shows phase and frequency correct pwm mode when ocr1a or icr1 is used to define top. the tcnt1 value is in the timing dia- gram shown as a histogram for illustrating the dual-slope operation. the diagram includes non- inverted and inverted pwm outputs. the small horizontal line marks on the tcnt1 slopes repre- sent compare matches between ocr1x and tcnt1. the oc1x interrupt flag will be set when a compare match occurs. figure 13-20. phase and frequency correct pwm mode, timing diagram the timer/counter overflow flag (tov1) is set at the same timer clock cycle as the ocr1x registers are updated with the double buffer value (at bottom). when either ocr1a or icr1 is used for defining the top value, the oc1a or icf1 flag set when tcnt1 has reached top. the interrupt flags can then be used to generate an interrupt each time the counter reaches the top or bottom value. when changing the top value the program must ensure that the new top value is higher or equal to the value of all of the compare registers. if the top value is lower than any of the compare registers, a compare match will never occur between the tcnt1 and the ocr1x. as figure 13-20 shows the output generated is, in contrast to the phase correct mode, symmet- rical in all periods. since the ocr1x registers are updated at bottom, the length of the rising and the falling slopes will always be equal. this gives symmetrical output pulses and is therefore frequency correct. using the icr1 register for defining top works well when using fixed top values. by using icr1, the ocr1a register is free to be used for generating a pwm output on oc1a. however, r pfcpwm top 1 + () log 2 () log ---------------------------------- - = ocr1x/top updateand tov1 interrupt flag set (interrupt on bottom) oc1a interrupt flag set or icf1 interrupt flag set (interrupt on top) 1 2 3 4 tcnt1 period oc1x oc1x (com1x1:0 = 2) (com1x1:0 = 3)
at90scr100/116/132 132 tpr0327b ? vic ? 16fev11 if the base pwm frequency is actively changed by changing the top value, using the ocr1a as top is clearly a better choice due to its double buffer feature. in phase and frequency correct pwm mode, the compare units allow generation of pwm wave- forms on the oc1x pins. setting the com1x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com1x1:0 to three (see table on page 135 ). the actual oc1x value will only be visible on the port pin if the data direction for the port pin is set as output (ddr_oc1x). the pwm waveform is generated by setting (or clearing) the oc1x register at the compare match between ocr1x and tcnt1 when the counter incre- ments, and clearing (or setting) the oc1x register at compare match between ocr1x and tcnt1 when the counter decrements. the pwm frequency for the output when using phase and frequency correct pwm can be calculated by the following equation: the n variable represents the prescaler divider (1, 8, 64, 256, or 1024). the extreme values for the ocr1x register represents special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr1x is set equal to bottom the output will be continuously low and if set equal to top the output will be set to high for non- inverted pwm mode. for inverted pwm the output will have the opposite logic values. if ocr1a is used to define the top value (wgm13:0 = 9) and com1a1:0 = 1, the oc1a output will toggle with a 50% duty cycle. 13.2.9 timer/counter timing diagrams the timer/counter is a synchronous design and the timer clock (clk tn ) is therefore shown as a clock enable signal in the following figures. the figures include information on when interrupt flags are set, and when the ocr1x register is updated with the ocr1x buffer value (only for modes utilizing double buffering). figure 13-21 shows a timing diagram for the setting of ocf1x. figure 13-21. timer/counter timing diagram, setting of ocf1x, no prescaling figure 13-22 shows the same timing data, but with the prescaler enabled. f ocnxpfcpwm f clk_i/o 2 ntop ?? --------------------------- - = clk tn (clk i/o /1) ocf1x clk i/o ocr1x tcnt1 ocr1x value ocr1x - 1 ocr1x ocr1x + 1 ocr1x + 2
133 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 figure 13-22. timer/counter timing diagram, setting of ocf1x, with prescaler (f clk_i/o /8) figure 13-23 shows the count sequence close to top in various modes. when using phase and frequency correct pwm mode the ocr1x register is updated at bottom. the timing diagrams will be the same, but top should be replaced by bottom, top-1 by bottom+1 and so on. the same renaming applies for modes that set the tov1 flag at bottom. figure 13-23. timer/counter timing diagram, no prescaling figure 13-24 shows the same timing data, but with the prescaler enabled. ocf1x ocr1x tcnt1 ocr1x value ocr1x - 1 ocr1x ocr1x + 1 ocr1x + 2 clk i/o clk tn (clk i/o /8) tov1 (fpwm) and icf1 (if used as top) ocr1x (update at top) tcnt1 (ctc and fpwm) tcnt1 (pc and pfc pwm) top - 1 top top - 1 top - 2 old ocr1x value new ocr1x value top - 1 top bottom bottom + 1 clk tn (clk i/o /1) clk i/o
at90scr100/116/132 134 tpr0327b ? vic ? 16fev11 figure 13-24. timer/counter timing diagram, with prescaler (f clk_i/o /8) 13.2.10 16-bit timer/counter register description 13.2.10.1 tccr1a ? timer/counter1 control register a ? bit 7..6 ? com1a1..0: compar e output mode for channel a ? bit 5..4 ? com1b1..0: compar e output mode for channel b the com1a1:0 and com1b1:0 control the output compare pins (oc1a and oc1b respec- tively) behavior. if one or both of the com1a1:0 bits are written to one, the oc1a output overrides the normal port functionality of the i/o pin it is connected to. if one or both of the com1b1:0 bit are written to one, the oc1b output overrides the normal port functionality of the i/o pin it is connected to. however, note that the data direction register (ddr) bit correspond- ing to the oc1a or oc1b pin must be set in order to enable the output driver. when the oc1a or oc1b is connected to the pin, the function of the com1x1:0 bits is depen- dent of the wgm13:0 bits setting. table 13-11 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to a normal or a ctc mode (non-pwm). tov1 (fpwm) and icf1 (if used as top) ocr1x (update at top) tcnt1 (ctc and fpwm) tcnt1 (pc and pfc pwm) top - 1 top top - 1 top - 2 old ocr1x value new ocr1x value top - 1 top bottom bottom + 1 clk i/o clk tn (clk i/o /8) bit 76543 2 10 $000080 com1a1 com1a0 com1b1 com1b0 - - wgm11 wgm10 tccr1a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 table 13-11. compare output mode, non-pwm com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 0 1 toggle oc1a/oc1b on compare match. 10 clear oc1a/oc1b on compare match (set output to low level). 11 set oc1a/oc1b on compare match (set output to high level).
135 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 table 13-12 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to the fast pwm mode. note: 1. a special case occurs when ocr1a/ocr1b equals top and com1a1/com1b1 is set. in this case the compare match is ignored, but the set or clear is done at top. see ?fast pwm mode? on page 126. for more details. table 13-13 shows the com1x1:0 bit functionality when the wgm13:0 bits are set to the phase correct or the phase and frequency correct, pwm mode. note: 1. a special case occurs when ocr1a/ocr1b equals top and com1a1/com1b1 is set. see ?phase correct pwm mode? on page 128. for more details. ? bit 1..0 ? wgm11..0: waveform generation mode combined with the wgm13:2 bits found in the tccr1b register, these bits control the counting sequence of the counter, the source for maximum (top) counter value, and what type of wave- form generation to be used, see table 13-14 . modes of operation supported by the timer/counter unit are: normal mode (counter), clear timer on compare match (ctc) mode, and three types of pulse width modulation (pwm) modes. ( see ?modes of operation? on page 125. ). table 13-12. compare output mode, fast pwm (1) com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 01 wgm13:0 = 14 or 15: toggle oc1a on compare match, oc1b disconnected (normal port operation). for all other wgm1 settings, normal port operation, oc1a/oc1b disconnected. 10 clear oc1a/oc1b on compare match, set oc1a/oc1b at bottom (non-inverting mode) 11 set oc1a/oc1b on compare match, clear oc1a/oc1b at bottom (inverting mode) table 13-13. compare output mode, phase correct and phase and frequency correct pwm (1) com1a1/com1b1 com1a0/com1b0 description 0 0 normal port operation, oc1a/oc1b disconnected. 01 wgm13:0 = 9 or 11: toggle oc1a on compare match, oc1b disconnected (normal port operation). for all other wgm1 settings, normal port operation, oc1a/oc1b disconnected. 10 clear oc1a/oc1b on compare match when up- counting. set oc1a/oc1b on compare match when downcounting. 11 set oc1a/oc1b on compare match when up- counting. clear oc1a/oc1b on compare match when downcounting.
at90scr100/116/132 136 tpr0327b ? vic ? 16fev11 note: 1. the ctcn and pwmn1:0 bit definition names are obsolete. use the wgm12:0 definitions. however, the functionality and location of these bits are compatible with previous versions of the timer. 13.2.10.2 tccr1b ? timer/counter1 control register b ? bit 7 ? icncn: input capture noise canceler setting this bit (to one) activates the input capture noise canceler. when the noise canceler is activated, the input from the input capture pin (icp1) is filtered. the filter function requires four successive equal valued samples of the icp1 pin for changing its output. the input capture is therefore delayed by four oscillator cycles when the noise canceler is enabled. ? bit 6 ? icesn: input capture edge select this bit selects which edge on the input capture pin (icp1) that is used to trigger a capture event. when the icesn bit is written to zero, a falling (negative) edge is used as trigger, and when the icesn bit is written to one, a rising (positive) edge will trigger the capture. when a capture is triggered according to the icesn setting, the counter value is copied into the input capture register (icr1). the event will also set the input capture flag (icf1), and this can be used to cause an input capture interrupt, if this interrupt is enabled. table 13-14. waveform generation mode bit description (1) mode wgm13 wgm12 (ctcn) wgm11 (pwmn1) wgm10 (pwmn0) timer/counter mode of operation top update of ocr1 x at tov1 flag set on 0 0 0 0 0 normal 0xffff immediate max 1 0 0 0 1 pwm, phase correct, 8-bit 0x00ff top bottom 2 0 0 1 0 pwm, phase correct, 9-bit 0x01ff top bottom 3 0 0 1 1 pwm, phase correct, 10-bit 0x03ff top bottom 4 0 1 0 0 ctc ocr1a immediate max 5 0 1 0 1 fast pwm, 8-bit 0x00ff bottom top 6 0 1 1 0 fast pwm, 9-bit 0x01ff bottom top 7 0 1 1 1 fast pwm, 10-bit 0x03ff bottom top 81 0 0 0 pwm, phase and frequency correct icr1 bottom bottom 91 0 0 1 pwm, phase and frequency correct ocr1a bottom bottom 10 1 0 1 0 pwm, phase correct icr1 top bottom 11 1 0 1 1 pwm, phase correct ocr1a top bottom 12 1 1 0 0 ctc icr1 immediate max 13 1 1 0 1 (reserved) ? ? ? 141110fast pwm icr1bottomtop 151111fast pwm ocr1abottomtop bit 76543 2 10 $000081 icnc1 ices1 - wgm13 wgm12 cs12 cs11 cs10 tccr1b read/write r/w r/w r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
137 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 when the icr1 is used as top value (see description of the wgm13:0 bits located in the tccr1a and the tccr1b register), the icp1 is disconnected and consequently the input cap- ture function is disabled. ? bit 5 ? reserved bit this bit is reserved for future use. for ensuring compatibility with future devices, this bit must be written to zero when tccr1b is written. ? bit 4..3 ? wgm13..2: waveform generation mode see tccr1a register description. ? bit 2..0 ? cs12..0: clock select the three clock select bits select the clock source to be used by the timer/counter, see figure 13-21 and figure 13-22 . if external pin modes are used for the timer/countern, transitions on the tn pin will clock the counter even if the pin is configured as an output. this feature allows software control of the counting. 13.2.10.3 tccr1c ? timer/counter1 control register c ? bit 7 ? foc1a: force output compare for channel a ? bit 6 ? foc1b: force output compare for channel b the foc1a/foc1b bits are only active when the wgm13:0 bits specifies a non-pwm mode. however, for ensuring compatibility with future devices, these bits must be set to zero when tccr1a is written when operating in a pwm mode. when writing a logical one to the foc1a/foc1b bit, an immediate compare match is forced on the waveform generation unit. the oc1a/oc1b output is changed according to its com1x1:0 bits setting. note that the foc1a/foc1b bits are implemented as strobes. therefore it is the value present in the com1x1:0 bits that determine the effect of the forced compare. table 13-15. clock select bit description cs12 cs11 cs10 description 0 0 0 no clock source (timer/counter stopped). 001clk i/o /1 (no prescaling) 010clk i/o /8 (from prescaler) 011clk i/o /64 (from prescaler) 100clk i/o /256 (from prescaler) 101clk i/o /1024 (from prescaler) 1 1 0 external clock source on tn pin. clock on falling edge. 1 1 1 external clock source on tn pin. clock on rising edge. bit 76543 2 10 $000082 foc1a foc1b - - - - - - tccr1c read/write r/w r/w r r r r r r initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 138 tpr0327b ? vic ? 16fev11 a foc1a/foc1b strobe will not generate any interrupt nor will it clear the timer in clear timer on compare match (ctc) mode using ocr1a as top. the foc1a/foc1b bits are always read as zero. 13.2.10.4 tcnt1h and tcnt1l ?timer/counter1 the two timer/counter i/o locations (tcnt1h and tcnt1l, combined tcnt1) give direct access, both for read and for write operations, to the timer/counter unit 16-bit counter. to ensure that both the high and low bytes are read and written simultaneously when the cpu accesses these registers, the access is performed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16-bit registers. see ?accessing 16-bit registers? on page 115. modifying the counter (tcnt1) while the counter is running introduces a risk of missing a com- pare match between tcnt1 and one of the ocr1x registers. writing to the tcnt1 register blocks (removes) the compare match on the following timer clock for all compare units. bit 1514131211 10 9 8 $000085 tcnt[15..8] tcnt1h $000084 tcnt [7..0] tcnt1l bit 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 value 0 0 0 0 0 0 0 0 0x00 00000 0 00 0x00
139 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.2.10.5 ocr1ah and ocr1al ? output compare register 1 a 13.2.10.6 ocr1bh and ocr1bl ? output compare register 1 b the output compare registers contain a 16-bit value that is continuously compared with the counter value (tcnt1). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc1x pin. the output compare registers are 16-bit in size. to ensure that both the high and low bytes are written simultaneously when the cpu writes to these registers, the access is performed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16-bit registers. see ?accessing 16-bit registers? on page 115. 13.2.10.7 icr1h and icr1l ? input capture register 1 the input capture is updated with the counter (tcnt1) value each time an event occurs on the icp1 pin. the input capture can be used for defining the counter top value. the input capture register is 16-bit in size. to ensure that both the high and low bytes are read simultaneously when the cpu accesses these registers, the access is performed using an 8-bit temporary high byte register (temp). this temporary register is shared by all the other 16-bit registers. see ?accessing 16-bit registers? on page 115. bit 1514131211 10 9 8 $000089 ocr1a[15..8] ocr1ah $000088 ocr1a [7..0] ocr1al bit 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 value 0 0 0 0 0 0 0 0 0x00 00000 0 00 0x00 bit 1514131211 10 9 8 $00008b ocr1b[15..8] ocr1bh $00008a ocr1b [7..0] ocr1bl bit 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 value 0 0 0 0 0 0 0 0 0x00 00000 0 00 0x00 bit 1514131211 10 9 8 $000087 icr1[15..8] icr1h $000086 icr1 [7..0] icr1l bit 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 value 0 0 0 0 0 0 0 0 0x00 00000 0 00 0x00
at90scr100/116/132 140 tpr0327b ? vic ? 16fev11 13.2.10.8 timsk1 ? timer/counter1 interrupt mask register ? bit 7..6 ? res: reserved bits these bits are unused bits in the at90scr100/116/132, and will always read as zero. ? bit 5 ? icie1: timer/counter1, input capture interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 input capture interrupt is enabled. the corresponding interrupt vector ( see ?interrupts? on page 71. ) is executed when the icf1 flag, located in tifr1, is set. ? bit 4..3 ? res: reserved bits these bits are unused bits in the at90scr100/116/132, and will always read as zero. ? bit 2 ? ocie1b: timer/counter1, output compare b match interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 output compare b match interrupt is enabled. the corresponding interrupt vector ( see ?interrupts? on page 71. ) is executed when the ocf1b flag, located in tifr1, is set. ? bit 1 ? ocie1a: timer/counter1, output compare a match interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 output compare a match interrupt is enabled. the corresponding interrupt vector ( see ?interrupts? on page 71. ) is executed when the ocf1a flag, located in tifr1, is set. ? bit 0 ? toie1: timer/counter1, overflow interrupt enable when this bit is written to one, and the i-flag in the status register is set (interrupts globally enabled), the timer/counter1 overflow interrupt is enabled. the corresponding interrupt vector ( see ?watchdog timer? on page 65. ) is executed when the tov1 flag, located in tifr1, is set. 13.2.10.9 tifr1 ? timer/counter1 interrupt flag register ? bit 7..6 ? res: reserved bits these bits are unused bits in the at90scr100/116/132, and will always read as zero. ? bit 5 ? icf1: timer/counter1, input capture flag this flag is set when a capture event occurs on the icp1 pin. when the input capture register (icr1) is set by the wgm13:0 to be used as the top value, the icf1 flag is set when the coun- ter reaches the top value. bit 76543 2 10 $00006f - - icie1 - - ocie1b ocie1a toie1 timsk1 read/write r r r/w r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 $000016 --icf1--ocf1bocf1atov1tifr1 read/write r r r/w r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
141 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 icf1 is automatically cleared when the input capture interrupt vector is executed. alternatively, icf1 can be cleared by writing a logic one to its bit location. ? bit 4..3 ? res: reserved bits these bits are unused bits in the at90scr100/116/132, and will always read as zero. ? bit 2 ? ocf1b: timer/counter1, output compare b match flag this flag is set in the timer clock cycle afte r the counter (tcnt1) value matches the output compare register b (ocr1b). note that a forced output compare (foc1b) strobe will not set the ocf1b flag. ocf1b is automatically cleared when the output compare match b interrupt vector is exe- cuted. alternatively, ocf1b can be cleared by writing a logic one to its bit location. ? bit 1 ? ocf1a: timer/counter1, output compare a match flag this flag is set in the timer clock cycle afte r the counter (tcnt1) value matches the output compare register a (ocr1a). note that a forced output compare (foc1a) strobe will not set the ocf1a flag. ocf1a is automatically cleared when the output compare match a interrupt vector is exe- cuted. alternatively, ocf1a can be cleared by writing a logic one to its bit location. ? bit 0 ? tov1: timer/counter1, overflow flag the setting of this flag is dependent of the wg m13:0 bits setting. in normal and ctc modes, the tov1 flag is set when the timer overflows. refer to table 13-14 on page 136 for the tov1 flag behavior when using another wgm13:0 bit setting. tov1 is automatically cleared when the timer/counter1 overflow interrupt vector is executed. alternatively, tov1 can be cleared by writing a logic one to its bit location.
at90scr100/116/132 142 tpr0327b ? vic ? 16fev11 13.3 8-bit timer/counter2 with pwm and asynchronous operation (rtc) timer/counter2 is a general purpose, single channel, 8-bit timer/counter module. the main features are: ? single channel counter ? clear timer on compare match (auto reload) ? glitch-free, phase correct pulse width modulator (pwm) ? frequency generator ? 10-bit clock prescaler ? overflow and compare match interrupt sources (tov2, ocf2a and ocf2b) ? allows clocking from external 32 khz watch crystal independent of the i/o clock 13.3.1 overview a simplified block diagram of the 8-bit timer/counter is shown in figure 13-23 . for the actual placement of i/o pins, see ?pin list configuration? on page 15 . cpu accessible i/o registers, including i/o bits and i/o pins, are shown in bold. the device-specific i/o register and bit loca- tions are listed in the ?8-bit timer/counter register description? on page 153 . the power reduction timer/counter2 bit, prtim2, in ?prr0 ? power reduction register 0? on page 54 must be written to zero to enable timer/counter2 module. figure 13-25. 8-bit timer/counter block diagram timer/counter data bus ocr2a ocr2b = = tcnt2 waveform generation waveform generation oc2a oc2b = fixed top value control logic = 0 top bottom count clear direction tov2 (int.req.) oc2a (int.req.) oc2b (int.req.) tccr2a tccr2b clk tn assr synchronization unit prescaler t/c oscillator clk i/o clk asy asynchronous mode select (as2) synchronized status flags tosc1 tosc2 status flags clk i/o
143 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.3.1.1 registers the timer/counter (tcnt2) and output compare register (ocr2a and ocr2b) are 8-bit reg- isters. interrupt request (abbreviated to int.req.) signals are all visible in the timer interrupt flag register (tifr2). all interrupts are individua lly masked with the timer interrupt mask register (timsk2). tifr2 and timsk2 are not shown in the figure. the timer/counter can be clocked internally, via the prescaler, or asynchronously clocked from the tosc1/2 pins, as detailed later in this section. the asynchronous operation is controlled by the asynchronous status register (assr). the clock select logic block controls which clock source the timer/counter uses to increment (or decrement) its value. the timer/counter is inac- tive when no clock source is selected. the output from the clock select logic is referred to as the timer clock (clk t2 ). the double buffered output compare register (ocr2a and ocr2b) are compared with the timer/counter value at all times. the result of the compare can be used by the waveform gen- erator to generate a pwm or variable frequency output on the output compare pins (oc2a and oc2b). see ?output compare unit? on page 144. for details. the compare match event will also set the compare flag (ocf2a or ocf2b) which can be used to generate an output compare interrupt request. 13.3.1.2 definitions most register and bit references in this secti on are written in general form. a lower case ?x? replaces the output compare unit channel. the definitions in table 13-16 are also used extensively throughout the section. 13.3.2 timer/counter clock sources the timer/counter can be clocked by an inte rnal synchronous or an external asynchronous clock source. the clock source clk t2 is by default equal to the mcu clock, clk i/o . when the as2 bit in the assr register is written to logic one, the clock source is taken from the timer/counter oscillator connected to tosc1 and tosc2. for details on asynchronous operation, see ?assr ? asynchronous status register? on page 158 . for details on clock sources and prescaler, see ?timer/counter prescaler? on page 162 . 13.3.3 counter unit the main part of the 8-bit timer/counter is the programmable bi-directional counter unit. figure 13-26 shows a block diagram of the counter and its surrounding environment. table 13-16. definitions bottom the counter reaches the bottom when it becomes zero (0x00). max the counter reaches its maximum when it becomes 0xff (decimal 255). top the counter reaches the top when it becomes equal to the highest value in the count sequence. the top value can be assigned to be the fixed value 0xff (max) or the value stored in the ocr2a register. the assignment is depen- dent on the mode of operation.
at90scr100/116/132 144 tpr0327b ? vic ? 16fev11 figure 13-26. counter unit block diagram signal description (internal signals): count increment or decrement tcnt2 by 1. direction selects between increment and decrement. clear clear tcnt2 (set all bits to zero). clk tn timer/counter clock, referred to as clk t2 in the following. top signalizes that tcnt2 has reached maximum value. bottom signalizes that tcnt2 has reached minimum value (zero). depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clk t2 ). clk t2 can be generated from an external or internal clock source, selected by the clock select bits (cs22:0). when no clock source is selected (cs22:0 = 0) the timer is stopped. however, the tcnt2 value can be accessed by the cpu, regardless of whether clk t2 is present or not. a cpu write override s (has priority over) all counter clear or count operations. the counting sequence is determined by the setting of the wgm21 and wgm20 bits located in the timer/counter control register (tccr2a) and the wgm22 located in the timer/counter control register b (tccr2b). there are close connections between how the counter behaves (counts) and how waveforms are generated on the output compare outputs oc2a and oc2b. for more details about advanced counting sequences and waveform generation, see ?modes of operation? on page 147 . the timer/counter overflow flag (tov2) is set according to the mode of operation selected by the wgm22:0 bits. tov2 can be used for generating a cpu interrupt. 13.3.4 output compare unit the 8-bit comparator continuously compares tcnt2 with the output compare register (ocr2a and ocr2b). whenever tcnt2 equals ocr2a or ocr2b, the comparator signals a match. a match will set the output compare flag (ocf2a or ocf2b) at the next timer clock cycle. if the corresponding interrupt is enabled, the output compare flag generates an output compare interrupt. the output compare flag is automatically cleared when the interrupt is exe- cuted. alternatively, the output compare flag can be cleared by software by writing a logical one to its i/o bit location. the waveform generator uses the match signal to generate an output according to operating mode set by the wgm22:0 bits and compare output mode (com2x1:0) bits. the max and bottom signals are used by the waveform generator for handling the special cases of the extreme values in some modes of operation ( ?modes of operation? on page 147 ). figure 13-21 on page 132 shows a block diagram of the output compare unit. data bus tcnt2 control logic count tov2 (int.req.) top bottom direction clear tosc1 t/c oscillator tosc2 prescaler clk i/o clk tn
145 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 figure 13-27. output compare unit, block diagram the ocr2x register is double buffered when using any of the pulse width modulation (pwm) modes. for the normal and clear timer on compare (ctc) modes of operation, the double buffering is disabled. the double buffering synchronizes the update of the ocr2x compare register to either top or bottom of the counting sequence. the synchronization prevents the occurrence of odd-length, non-symmetrical pwm pulses, thereby making the output glitch-free. the ocr2x register access may seem complex, but this is not case. when the double buffering is enabled, the cpu has access to the ocr2x buffer register, and if double buffering is dis- abled the cpu will access the ocr2x directly. 13.3.4.1 force output compare in non-pwm waveform generation modes, the match output of the comparator can be forced by writing a one to the force output compare (foc2x) bit. forcing compare match will not set the ocf2x flag or reload/clear the timer, but the oc2x pin will be updated as if a real compare match had occurred (the com2x1:0 bits settings define whether the oc2x pin is set, cleared or toggled). 13.3.4.2 compare match blocking by tcnt2 write all cpu write operations to the tcnt2 register will block any compare match that occurs in the next timer clock cycle, even when the timer is stopped. this feature allows ocr2x to be initial- ized to the same value as tcnt2 without triggering an interrupt when the timer/counter clock is enabled. 13.3.4.3 using the output compare unit since writing tcnt2 in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing tcnt2 when using the output compare channel, independently of whether the timer/counter is running or not. if the value written to tcnt2 equals the ocr2x value, the compare match will be missed, resulting in incorrect waveform generation. similarly, do not write the tcnt2 value equal to bottom when the counter is downcounting. oc2 x (int.req.) = (8-bit comparator ) ocr2x oc2x data bus tcnt2 wgm21:0 waveform generator top foc2 com2x1:0 bottom
at90scr100/116/132 146 tpr0327b ? vic ? 16fev11 the setup of the oc2x should be performed before setting the data direction register for the port pin to output. the easiest way of setting the oc2x value is to use the force output com- pare (foc2x) strobe bit in normal mode. the oc2x register keeps its value even when changing between waveform generation modes. changing the com2x1:0 bits will take effect immediately. 13.3.5 compare match output unit the compare output mode (com2x1:0) bits have two functions. the waveform generator uses the com2x1:0 bits for defining the output compare (oc2x) state at the next compare match. also, the com2x1:0 bits contro l the oc2x pin output source. figure 13-28 shows a simplified schematic of the logic affected by the com2x1:0 bit setting. the i/o registers, i/o bits, and i/o pins in the figure are shown in bold. only the parts of the general i/o port control registers (ddr and port) that are affected by the com2x1:0 bits are shown. when referring to the oc2x state, the reference is for the internal oc2x register, not the oc2x pin. figure 13-28. compare match output unit, schematic the general i/o port function is overridden by the output compare (oc2x) from the waveform generator if either of the com2x1:0 bits are set. however, the oc2x pin direction (input or out- put) is still controlled by the data direction register (ddr) for the port pin. the data direction register bit for the oc2x pin must be set as output before the oc2x value is visible on the pin. the port override function is independent of the waveform generation mode. the design of the output compare pin logic allows initialization of the oc2x state before the out- put is enabled. note that some com2x1:0 bit settings are reserved for certain modes of operation. see ?8-bit timer/counter register description? on page 153. 13.3.5.1 compare output mode and waveform generation the waveform generator uses the com2x1:0 bits differently in normal, ctc, and pwm modes. for all modes, setting the com2x1:0 = 0 tells the waveform generator that no action on the port ddr dq dq oc2x pin oc2x dq waveform generator com2x1 com2x0 0 1 data bus foc2x clk i/o
147 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 oc2x register is to be performed on the next compare match. for compare output actions in the non-pwm modes refer to table 13-20 on page 154 . for fast pwm mode, refer to table 13-21 on page 154 , and for phase correct pwm refer to table 13-22 on page 155 . a change of the com2x1:0 bits state will have effect at the first compare match after the bits are written. for non-pwm modes, the action can be fo rced to have immediate effect by using the foc2x strobe bits. 13.3.6 modes of operation the mode of operation, i.e., the behavior of the timer/counter and the output compare pins, is defined by the combination of the waveform generation mode (wgm22:0) and compare output mode (com2x1:0) bits. the compare output mode bits do not affect the counting sequence, while the waveform generation mode bits do. the com2x1:0 bits control whether the pwm out- put generated should be inverted or not (inverted or non-inverted pwm). for non-pwm modes the com2x1:0 bits control whether the output should be set, cleared, or toggled at a compare match ( see ?compare match output unit? on page 146. ). for detailed timing information refer to ?timer/counter timing diagrams? on page 151 . 13.3.6.1 normal mode the simplest mode of operation is the normal mode (wgm22:0 = 0). in this mode the counting direction is always up (incrementing), and no counter clear is performed. the counter simply overruns when it passes its maximum 8-bit value (top = 0xff) and then restarts from the bot- tom (0x00). in normal operation the timer/counter overflow flag (tov2) will be set in the same timer clock cycle as the tcnt2 becomes zero. the tov2 flag in this case behaves like a ninth bit, except that it is only set, not cleared. howe ver, combined with the timer overflow interrupt that automatically clears the tov2 flag, the timer resolution can be increased by software. there are no special cases to consider in the normal mode, a new counter value can be written anytime. the output compare unit can be used to generate interrupts at some given time. using the out- put compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the cpu time. 13.3.6.2 clear timer on compare match (ctc) mode in clear timer on compare or ctc mode (wgm22:0 = 2), the ocr2a register is used to manipulate the counter resolution. in ctc mode the counter is cleared to zero when the counter value (tcnt2) matches the ocr2a. the ocr2a defines the top value for the counter, hence also its resolution. this mode allows greater control of the compare match output frequency. it also simplifies the operation of counting external events. the timing diagram for the ctc mode is shown in table 13-29 . the counter value (tcnt2) increases until a compare match occurs between tcnt2 and ocr2a, and then counter (tcnt2) is cleared.
at90scr100/116/132 148 tpr0327b ? vic ? 16fev11 figure 13-29. ctc mode, timing diagram an interrupt can be generated each time the counter value reaches the top value by using the ocf2a flag. if the interrupt is enabled, the interrupt handler routine can be used for updating the top value. however, changing top to a value close to bottom when the counter is run- ning with none or a low prescaler value must be done with care since the ctc mode does not have the double buffering feature. if the new value written to ocr2a is lower than the current value of tcnt2, the counter will miss the compare match. the counter will then have to count to its maximum value (0xff) and wrap around starting at 0x00 before the compare match can occur. for generating a waveform output in ctc mode, the oc2a output can be set to toggle its logical level on each compare match by setting the compare output mode bits to toggle mode (com2a1:0 = 1). the oc2a value will not be visible on the port pin unless the data direction for the pin is set to output. the waveform generated will have a maximum frequency of f oc2a = f clk_i/o /2 when ocr2a is set to zero (0x00). the waveform frequency is defined by the following equation: the n variable represents the prescale factor (1, 8, 32, 64, 128, 256, or 1024). as for the normal mode of operation, the tov2 flag is set in the same timer clock cycle that the counter counts from max to 0x00. 13.3.6.3 fast pwm mode the fast pulse width modulation or fast pwm mode (wgm22:0 = 3 or 7) provides a high fre- quency pwm waveform generation option. the fast pwm differs from the other pwm option by its single-slope operation. the counter counts from bottom to top then restarts from bot- tom. top is defined as 0xff when wgm22:0 = 3, and ocr2a when mgm22:0 = 7. in non- inverting compare output mode, the output compare (oc2x) is cleared on the compare match between tcnt2 and ocr2x, and set at bottom. in inverting compare output mode, the out- put is set on compare match and cleared at bottom. due to the single-slope operation, the operating frequency of the fast pwm mode can be twice as high as the phase correct pwm mode that uses dual-slope operation. this high frequency makes the fast pwm mode well suited for power regulation, rectification, and dac applications. high frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost. in fast pwm mode, the counter is incremented until the counter value matches the top value. the counter is then cleared at the following timer clock cycle. the timing diagram for the fast tcnt2 oc2x (toggle) oc2x interrupt flag set 1 4 period 2 3 (com2x1:0 = 1) f ocnx f clk_i/o 2 n 1 ocrnx + () ?? ------------------------------------------------- - =
149 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 pwm mode is shown in figure 13-30 on page 149 . the tcnt2 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. the diagram includes non- inverted and inverted pwm outputs. the small horizontal line marks on the tcnt2 slopes repre- sent compare matches between ocr2x and tcnt2. figure 13-30. fast pwm mode, timing diagram the timer/counter overflow flag (tov2) is set each time the counter reaches top. if the inter- rupt is enabled, the interrupt handler routine can be used for updating the compare value. in fast pwm mode, the compare unit allows generation of pwm waveforms on the oc2x pin. setting the com2x1:0 bits to two will produce a non-inverted pwm and an inverted pwm output can be generated by setting the com2x1:0 to three. top is defined as 0xff when wgm2:0 = 3, and ocr2a when wgm2:0 = 7 (see table 13-18 on page 153 ). the actual oc2x value will only be visible on the port pin if the data direction for the port pin is set as output. the pwm wave- form is generated by setting (or clearing) the oc2x register at the compare match between ocr2x and tcnt2, and clearing (or setting) the oc2x register at the timer clock cycle the counter is cleared (changes from top to bottom). the pwm frequency for the output can be calculated by the following equation: the n variable represents the prescale factor (1, 8, 32, 64, 128, 256, or 1024). the extreme values for the ocr2a register represent special cases when generating a pwm waveform output in the fast pwm mode. if the ocr2a is set equal to bottom, the output will be a narrow spike for each max+1 timer clock cycle. setting the ocr2a equal to max will result in a constantly high or low output (depending on the polarity of the output set by the com2a1:0 bits.) a frequency (with 50% duty cycle) waveform output in fast pwm mode can be achieved by set- ting oc2x to toggle its logical level on each compare match (com2x1:0 = 1). the waveform generated will have a maximum frequency of f oc2 = f clk_i/o /2 when ocr2a is set to zero. this fea- ture is similar to the oc2a toggle in ctc mode, except the double buffer feature of the output compare unit is enabled in the fast pwm mode. tcnt2 ocr2x update and tov2 interrupt flag set 1 period 2 3 oc2x oc2x (com2x1:0 = 2) (com2x1:0 = 3) ocr2x interrupt flag set 4 5 6 7 f ocnxpwm f clk_i/o n 256 ? ------------------ =
at90scr100/116/132 150 tpr0327b ? vic ? 16fev11 13.3.6.4 phase correct pwm mode the phase correct pwm mode (wgm22:0 = 1 or 5) provides a high resolution phase correct pwm waveform generation option. the phase correct pwm mode is based on a dual-slope operation. the counter counts repeatedly from bottom to top and then from top to bot- tom. top is defined as 0xff when wgm22:0 = 1, and ocr2a when mgm22:0 = 5. in non- inverting compare output mode, the output compare (oc2x) is cleared on the compare match between tcnt2 and ocr2x while upcounting, and set on the compare match while downcount- ing. in inverting output compare mode, the operation is inverted. the dual-slope operation has lower maximum operation frequency than single slope operation. however, due to the symmet- ric feature of the dual-slope pwm modes, these modes are preferred for motor control applications. in phase correct pwm mode the counter is incremented until the counter value matches top. when the counter reaches top, it changes the count direction. the tcnt2 value will be equal to top for one timer clock cycle. the timing diagram for the phase correct pwm mode is shown on figure 13-31 . the tcnt2 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. the diagram includes non-inverted and inverted pwm outputs. the small horizontal line marks on the tcnt2 slopes represent compare matches between ocr2x and tcnt2. figure 13-31. phase correct pwm mode, timing diagram the timer/counter overflow flag (tov2) is set each time the counter reaches bottom. the interrupt flag can be used to generate an interrupt each time the counter reaches the bottom value. in phase correct pwm mode, the compare unit allows generation of pwm waveforms on the oc2x pin. setting the com2x1:0 bits to two will produce a non-inverted pwm. an inverted pwm output can be generated by setting the com2x1:0 to three. top is defined as 0xff when wgm2:0 = 3, and ocr2a when mgm2:0 = 7 (see table 13-19 on page 154 ). the actual oc2x value will only be visible on the port pin if the data direction for the port pin is set as output. the pwm waveform is generated by clearing (or setting) the oc2x register at the compare match tov2 interrupt flag set oc2x interrupt flag set 1 2 3 tcnt2 period oc2x oc2x (com2x1:0 = 2) (com2x1:0 = 3) ocr2x update
151 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 between ocr2x and tcnt2 when the counter increments, and setting (or clearing) the oc2x register at compare match between ocr2x and tcnt2 when the counter decrements. the pwm frequency for the output when using phase correct pwm can be calculated by the follow- ing equation: the n variable represents the prescale factor (1, 8, 32, 64, 128, 256, or 1024). the extreme values for the ocr2a register represent special cases when generating a pwm waveform output in the phase correct pwm mode. if the ocr2a is set equal to bottom, the output will be continuously low and if set equal to max the output will be continuously high for non-inverted pwm mode. for inverted pwm the output will have the opposite logic values. at the very start of period 2 in figure 13-31 oc2x has a transition from high to low even though there is no compare match. the point of this transition is to guarantee symmetry around bot- tom. there are two cases that give a transition without compare match. ? ocr2a changes its value from max, like in figure 13-31 . when the ocr2a value is max the oc2 pin value is the same as the result of a down-counting compare match. to ensure symmetry around bottom the oc2 value at max must correspond to the result of an up- counting compare match. ? the timer starts counting from a value higher than the one in ocr2a, and for that reason misses the compare match and hence the oc2 change that would have happened on the way up. 13.3.7 timer/counter timing diagrams the following figures show the timer/counter in synchronous mode, and the timer clock (clk t2 ) is therefore shown as a clock enable signal. in asynchronous mode, clk i/o should be replaced by the timer/counter oscillator clock. the figures include information on when interrupt flags are set. figure 13-32 contains timing data for basic timer/counter operation. the figure shows the count sequence close to the max value in all modes other than phase correct pwm mode. figure 13-32. timer/counter timing diagram, no prescaling figure 13-33 shows the same timing data, but with the prescaler enabled. f ocnxpcpwm f clk_i/o n 510 ? ------------------ = clk tn (clk i/o /1) tov2 clk i/o tcnt2 max - 1 max bottom bottom + 1
at90scr100/116/132 152 tpr0327b ? vic ? 16fev11 figure 13-33. timer/counter timing diagram, with prescaler (f clk_i/o /8) figure 13-34 shows the setting of ocf2a in all modes except ctc mode. figure 13-34. timer/counter timing diagram, setting of ocf2a, with prescaler (f clk_i/o /8) figure 13-35 shows the setting of ocf2a and the clearing of tcnt2 in ctc mode. figure 13-35. timer/counter timing diagram, clear timer on compare match mode, with pres- caler (f clk_i/o /8) tov2 tcnt2 max - 1 max bottom bottom + 1 clk i/o clk tn (clk i/o /8) ocf2x ocr2x tcnt2 ocr2x value ocr2x - 1 ocr2x ocr2x + 1 ocr2x + 2 clk i/o clk tn (clk i/o /8) ocf2x ocr2x tcnt2 (ctc) top top - 1 top bottom bottom + 1 clk i/o clk tn (clk i/o /8)
153 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 13.3.8 8-bit timer/counter register description 13.3.8.1 tccr2a ? timer/counter control register a ? bits 7..6 ? com2a1..0: compare match output a mode these bits control the output compare pin (oc2a) behavior. if one or both of the com2a1:0 bits are set, the oc2a output overrides the normal port functionality of the i/o pin it is connected to. however, note that the data direction register (ddr) bit corresponding to the oc2a pin must be set in order to enable the output driver. when oc2a is connected to the pin, the function of the com2a1:0 bits depends on the wgm22:0 bit setting. table 13-17 shows the com2a1:0 bit functionality when the wgm22:0 bits are set to a normal or ctc mode (non-pwm). table 13-18 shows the com2a1:0 bit functionality when the wgm21:0 bits are set to fast pwm mode. note: 1. a special case occurs when ocr2a equals top and com2a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see ?fast pwm mode? on page 148 for more details. bit 7 6 5 43210 $0000b0 com2a1 com2a0 com2b1 com2b0 - - wgm21 wgm20 tccr2a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 table 13-17. compare output mode, non-pwm mode com2a1 com2a0 description 0 0 normal port operation, oc0a disconnected. 0 1 toggle oc2a on compare match 1 0 clear oc2a on compare match 1 1 set oc2a on compare match table 13-18. compare output mode, fast pwm mode (1) com2a1 com2a0 description 0 0 normal port operation, oc2a disconnected. 01 wgm22 = 0: normal port operation, oc0a disconnected. wgm22 = 1: toggle oc2a on compare match. 10 clear oc2a on compare match, set oc2a at bottom (non-inverting mode) 11 set oc2a on compare match, clear oc2a at bottom (inverting mode)
at90scr100/116/132 154 tpr0327b ? vic ? 16fev11 table 13-19 shows the com2a1:0 bit functionality when the wgm22:0 bits are set to phase cor- rect pwm mode. note: 1. a special case occurs when ocr2a equals top and com2a1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see ?phase correct pwm mode? on page 150 for more details. ? bits 5..4 ? com2b1..0: compare match output b mode these bits control the output compare pin (oc2b) behavior. if one or both of the com2b1:0 bits are set, the oc2b output overrides the normal port functionality of the i/o pin it is connected to. however, note that the data direction register (ddr) bit corresponding to the oc2b pin must be set in order to enable the output driver. when oc2b is connected to the pin, the function of the com2b1:0 bits depends on the wgm22:0 bit setting. table 13-20 shows the com2b1:0 bit functionality when the wgm22:0 bits are set to a normal or ctc mode (non-pwm). table 13-21 shows the com2b1:0 bit functionality when the wgm22:0 bits are set to fast pwm mode. table 13-19. compare output mode, phase correct pwm mode (1) com2a1 com2a0 description 0 0 normal port operation, oc2a disconnected. 01 wgm22 = 0: normal port operation, oc2a disconnected. wgm22 = 1: toggle oc2a on compare match. 10 clear oc2a on compare match when up-counting. set oc2a on compare match when down-counting. 11 set oc2a on compare match when up-counting. clear oc2a on compare match when down-counting. table 13-20. compare output mode, non-pwm mode com2b1 com2b0 description 0 0 normal port operation, oc2b disconnected. 0 1 toggle oc2b on compare match 1 0 clear oc2b on compare match 1 1 set oc2b on compare match table 13-21. compare output mode, fast pwm mode (1) com2b1 com2b0 description 0 0 normal port operation, oc2b disconnected. 01reserved 10 clear oc2b on compare match, set oc2b at bottom (non-inverting mode) 11 set oc2b on compare match, clear oc2b at bottom (inverting mode)
155 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 note: 1. a special case occurs when ocr2b equals top and com2b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at bottom. see ?fast pwm mode? on page 148 for more details. table 13-22 shows the com2b1:0 bit functionality when the wgm22:0 bits are set to phase cor- rect pwm mode. note: 1. a special case occurs when ocr2b equals top and com2b1 is set. in this case, the com- pare match is ignored, but the set or clear is done at top. see ?phase correct pwm mode? on page 150 for more details. ? bits 3..2 ? res: reserved bits these bits are reserved bits in the at90scr100/116/132 and will always read as zero. ? bits 1..0 ? wgm21..0: waveform generation mode combined with the wgm22 bit found in the tccr2b register, these bits control the counting sequence of the counter, the source for maximum (top) counter value, and what type of wave- form generation to be used, see table 13-23 . modes of operation supported by the timer/counter unit are: normal mode (counter), clear timer on compare match (ctc) mode, and two types of pulse width modulation (pwm) modes (see ?modes of operation? on page 147 ). note: 1. max= 0xff, bottom= 0x00 table 13-22. compare output mode, phase correct pwm mode (1) com2b1 com2b0 description 0 0 normal port operation, oc2b disconnected. 01reserved 10 clear oc2b on compare match when up-counting. set oc2b on compare match when down-counting. 11 set oc2b on compare match when up-counting. clear oc2b on compare match when down-counting. table 13-23. waveform generation mode bit description mode wgm22 wgm21 wgm20 timer/counter mode of operation top update of ocrx at tov flag set on (1) 0 0 0 0 normal 0xff immediate max 1001 pwm, phase correct 0xff top bottom 2 0 1 0 ctc ocr2a immediate max 3 0 1 1 fast pwm 0xff bottom max 4100reserved ? ? ? 5101 pwm, phase correct ocr2a top bottom 6110reserved ? ? ? 7 1 1 1 fast pwm ocr2a bottom top
at90scr100/116/132 156 tpr0327b ? vic ? 16fev11 13.3.8.2 tccr2b ? timer/counter control register b ? bit 7 ? foc2a: force output compare a the foc2a bit is only active when the wgm bits specify a non-pwm mode. however, for ensuring compatibility with future devices, this bit must be set to zero when tccr2b is written when operating in pwm mode. when writing a logical one to the foc2a bit, an immediate compare match is forced on the waveform generation unit. the oc2a output is changed according to its com2a1:0 bits setting. note that the foc2a bit is implemented as a strobe. therefore it is the value present in the com2a1:0 bits that determines the effect of the forced compare. a foc2a strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr2a as top. the foc2a bit is always read as zero. ? bit 6 ? foc2b: force output compare b the foc2b bit is only active when the wgm bits specify a non-pwm mode. however, for ensuring compatibility with future devices, this bit must be set to zero when tccr2b is written when operating in pwm mode. when writing a logical one to the foc2b bit, an immediate compare match is forced on the waveform generation unit. the oc2b output is changed according to its com2b1:0 bits setting. note that the foc2b bit is implemented as a strobe. therefore it is the value present in the com2b1:0 bits that determines the effect of the forced compare. a foc2b strobe will not generate any interrupt, nor will it clear the timer in ctc mode using ocr2b as top. the foc2b bit is always read as zero. ? bits 5..4 ? res: reserved bits these bits are reserved bits and will always read as zero. ? bit 3 ? wgm22: waveform generation mode see the description in the ?tccr2a ? timer/counter control register a? on page 153 . ? bit 2..0 ? cs22..0: clock select bit 7 6 5 4 3 2 1 0 $0000b1 foc2a foc2b - - wgm22 cs22 cs21 cs20 tccr2b read/write w w r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
157 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 the three clock select bits select the clock source to be used by the timer/counter, see table 13-24 . if external pin modes are used for the timer/counter0, transitions on the t0 pin will clock the counter even if the pin is configured as an output. this feature allows software control of the counting. 13.3.8.3 tcnt2 ? timer/counter register the timer/counter register gives direct access, both for read and write operations, to the timer/counter unit 8-bit counter. writing to the tcnt2 register blocks (removes) the compare match on the following timer clock. modifying the counter (tcnt2) while the counter is running, introduces a risk of missing a compare match between tcnt2 and the ocr2x registers. 13.3.8.4 ocr2a ? output compare register a the output compare register a contains an 8-bit value that is continuously compared with the counter value (tcnt2). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc2a pin. table 13-24. clock select bit description cs22 cs21 cs20 description 0 0 0 no clock source (timer/counter stopped). 001clk t2s /(no prescaling) 010clk t2s /8 (from prescaler) 011clk t2s /32 (from prescaler) 100clk t2s /64 (from prescaler) 101clk t2s /128 (from prescaler) 110clk t 2 s /256 (from prescaler) 111clk t 2 s /1024 (from prescaler) bit 7 6 5 4 3 2 1 0 $0000b2 tcnt2 [7..0] tcnt2 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 0x00 bit 7 6 5 4 3 2 1 0 $0000b3 ocr2a [7..0] ocr2a 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 0x00
at90scr100/116/132 158 tpr0327b ? vic ? 16fev11 13.3.8.5 ocr2b ? output compare register b the output compare register b contains an 8-bit value that is continuously compared with the counter value (tcnt2). a match can be used to generate an output compare interrupt, or to generate a waveform output on the oc2b pin. 13.3.9 asynchronous operation of the timer/counter 13.3.9.1 assr ? asynchronous status register ? bit 6 ? exclk: enable external clock input when exclk is written to one, and asynchronous clock is selected, the external clock input buf- fer is enabled and an external clock can be input on timer oscillator 1 (tosc1) pin instead of a 32 khz crystal. writing to exclk should be done before asynchronous operation is selected. note that the crystal oscillator will only run when this bit is zero. ? bit 5 ? as2: asynchronous timer/counter2 when as2 is written to zero, timer/counter2 is clocked from the i/o clock, clk i/o . when as2 is written to one, timer/counter2 is clocked from a crystal oscillator connected to the timer oscil- lator 1 (tosc1) pin. when the value of as2 is changed, the contents of tcnt2, ocr2a, ocr2b, tccr2a and tccr2b might be corrupted. ? bit 4 ? tcn2ub: timer/counter2 update busy when timer/counter2 operates asynchronously and tcnt2 is written, this bit becomes set. when tcnt2 has been updated from the temporary storage register, this bit is cleared by hard- ware. a logical zero in this bit indicates that tcnt2 is ready to be updated with a new value. ? bit 3 ? ocr2aub: output compare register2 update busy when timer/counter2 operates asynchronously and ocr2a is written, this bit becomes set. when ocr2a has been updated from the temporary storage register, this bit is cleared by hard- ware. a logical zero in this bit indicates that ocr2a is ready to be updated with a new value. ? bit 2 ? ocr2bub: output compare register2 update busy when timer/counter2 operates asynchronously and ocr2b is written, this bit becomes set. when ocr2b has been updated from the temporary storage register, this bit is cleared by hard- ware. a logical zero in this bit indicates that ocr2b is ready to be updated with a new value. ? bit 1 ? tcr2aub: timer/counter control register2 update busy when timer/counter2 operates asynchronously and t ccr2a is written, th is bit becomes set. when tccr2a has been updated from the temporary storage register, this bit is cleared by bit 7 6 5 4 3 2 1 0 $0000b4 ocr2b [7..0] ocr2b 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 0x00 bit 7 6 5 4 3 2 1 0 $0000b6 - exclk as2 tcn2ub ocr2aub ocr2bub tcr2aub tcr2bub assr read/write r r/w r/w r r r r r initial value 0 0 0 0 0 0 0 0 0x00
159 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 hardware. a logical zero in this bit indicates that tccr2a is ready to be updated with a new value. ? bit 0 ? tcr2bub: timer/counter control register2 update busy when timer/counter2 operates asynchronously and tccr2b is written, this bit becomes set. when tccr2b has been updated from the temporary storage register, this bit is cleared by hardware. a logical zero in this bit indicates that tccr2b is ready to be updated with a new value. if a write is performed to any of the five timer/counter2 registers while its update busy flag is set, the updated value might get corrupted and cause an unintentional interrupt to occur. the mechanisms for reading tcnt2, ocr2a, ocr2b, tccr2a and tccr2b are different. when reading tcnt2, the actual timer value is read. when reading ocr2a, ocr2b, tccr2a and tccr2b the value in the temporary storage register is read. 13.3.9.2 asynchronous operation of timer/counter2 when timer/counter2 operates asynchronously, some considerations must be taken. ? warning: when switching between asynchronous and synchronous clocking of timer/counter2, the timer registers tcnt2, ocr2x, and tccr2x might be corrupted. a safe procedure for switching clock source is: 1. disable the timer/counter2 interrupts by clearing ocie2x and toie2. 2. select clock source by setting as2 as appropriate. 3. write new values to tcnt2, ocr2x, and tccr2x. 4. to switch to asynchronous operation: wait for tcn2ub, ocr2xub, and tcr2xub. 5. clear the timer/counter2 interrupt flags. 6. enable interrupts, if needed. ? the cpu main clock frequency must be more than four times the oscillator frequency. ? when writing to one of the registers tcnt2, oc r2x, or tccr2x, the value is transferred to a temporary register, and latched after two positive edges on tosc1. the user should not write a new value before the contents of the temporary register have been transferred to its destination. each of the five mentioned registers have their individual temporary register, which means that e.g. writing to tcnt2 does not disturb an ocr2x write in progress. to detect that a transfer to the destination register has taken place, the asynchronous status register ? assr has been implemented. ? when entering power-save or adc noise reduction mode after having written to tcnt2, ocr2x, or tccr2x, the user must wait until the written register has been updated if timer/counter2 is used to wake up the device. otherwise, the mcu will enter sleep mode before the changes are effective. this is particularly important if any of the output compare2 interrupt is used to wake up the device, since the output compare function is disabled during writing to ocr2x or tcnt2. if the write cycle is not finished, and the mcu enters sleep mode before the corresponding ocr2xub bit returns to zero, the device will never receive a compare match interrupt, and the mcu will not wake up. ? if timer/counter2 is used to wake the device up from power-save or adc noise reduction mode, precautions must be taken if the user wants to re-enter one of these modes: the interrupt logic needs one tosc1 cycle to be reset. if the time between wake-up and re- entering sleep mode is less than one tosc1 cycle, the interrupt will not occur, and the
at90scr100/116/132 160 tpr0327b ? vic ? 16fev11 device will fail to wake up. if the user is in doubt whether the time before re-entering power- save or adc noise reduction mode is sufficient, the following algorithm can be used to ensure that one tosc1 cycle has elapsed: 1. write a value to tccr2x, tcnt2, or ocr2x. 2. wait until the corresponding update busy flag in assr returns to zero. 3. enter power-save or adc noise reduction mode. ? when the asynchronous operation is selected, the 32.768 khz oscillator for timer/counter2 is always running, except in power-down and standby modes. after a power-up reset or wake-up from power-down or standby mode, the user should be aware of the fact that this oscillator might take as long as one second to stabilize. the user is advised to wait for at least one second before using timer/counter2 after power-up or wake-up from power-down or standby mode. the contents of all timer/counter2 registers must be considered lost after a wake-up from power-down or standby mode due to unstable clock signal upon start-up, no matter whether the oscillator is in use or a clock signal is applied to the tosc1 pin. ? description of wake up from power-save or adc noise reduction mode when the timer is clocked asynchronously: when the interrupt condition is met, the wake up process is started on the following cycle of the timer clock, that is, the timer is always advanced by at least one before the processor can read the counter value. after wake-up, the mcu is halted for four cycles, it executes the interrupt routine, and resumes execution from the instruction following sleep. ? reading of the tcnt2 register shortly after wake-up from power-save may give an incorrect result. since tcnt2 is clocked on the asynchronous tosc clock, reading tcnt2 must be done through a register synchronized to the internal i/o clock domain. synchronization takes place for every rising tosc1 edge. when waking up from power-save mode, and the i/o clock (clk i/o ) again becomes active, tcnt2 will read as the previous value (before entering sleep) until the next rising tosc1 edge. the phase of the tosc clock after waking up from power-save mode is essentially unpredictable, as it depends on the wake-up time. the recommended procedure for reading tcnt2 is thus as follows: 1. write any value to either of the registers ocr2x or tccr2x. 2. wait for the corresponding update busy flag to be cleared. 3. read tcnt2. ? during asynchronous operation, the synchronization of the interrupt flags for the asynchronous timer takes 3 processor cycles plus one timer cycle. the timer is therefore advanced by at least one before the processor can read the timer value causing the setting of the interrupt flag. the output compare pin is changed on the timer clock and is not synchronized to the processor clock. 13.3.9.3 timsk 2 ? timer/counter 2 interrupt mask register bit 7 6 5 4 3 2 1 0 $000070 - - - - - ocie2b ocie2a toie2 timsk2 read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
161 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 ? bit 2 ? ocie2b : timer/counter2 output compare match b interrupt enable when the ocie2b bit is written to one and the i-bit in the status register is set (one), the timer/counter2 compare match b interrupt is enabled. the corresponding interrupt is executed if a compare match in timer/counter2 occurs, i.e., when the ocf2b bit is set in the timer/coun- ter 2 interrupt flag register ? tifr2. ? bit 1 ? ocie2a : timer/counter2 output compare match a interrupt enable when the ocie2a bit is written to one and the i-bit in the status register is set (one), the timer/counter2 compare match a interrupt is enabled. the corresponding interrupt is executed if a compare match in timer/counter2 occurs, i.e., when the ocf2a bit is set in the timer/coun- ter 2 interrupt flag register ? tifr2. ? bit 0 ? toie2 : timer/counter2 overflow interrupt enable when the toie2 bit is written to one and the i-bit in the status register is set (one), the timer/counter2 overflow interrupt is enabled. the corresponding interrupt is executed if an overflow in timer/counter2 occurs, i.e., when the tov2 bit is set in the timer/counter2 interrupt flag register ? tifr2. 13.3.9.4 tifr 2 ? timer/counter 2 interrupt flag register ? bit 2 ? ocf2b : output compare flag 2 b the ocf2b bit is set (one) when a compare match occurs between the timer/counter2 and the data in ocr2b ? output compare register2. ocf2b is cleared by hardware when executing the corresponding interrupt handling vector. alter natively, ocf2b is cleared by writing a logic one to the flag. when the i-bit in sreg, ocie2b (timer/counter2 compare match interrupt enable), and ocf2b are set (one), the timer/counter2 compare match interrupt is executed. ? bit 1 ? ocf2a : output compare flag 2 a the ocf2a bit is set (one) when a compare match occurs between the timer/counter2 and the data in ocr2a ? output compare register2. ocf2a is cleared by hardware when executing the corresponding interrupt handling vector. alter natively, ocf2a is cleared by writing a logic one to the flag. when the i-bit in sreg, ocie2a (timer/counter2 compare match interrupt enable), and ocf2a are set (one), the timer/counter2 compare match interrupt is executed. ? bit 0 ? tov2 : timer/counter2 overflow flag the tov2 bit is set (one) when an overflow occurs in timer/counter2. tov2 is cleared by hard- ware when executing the corresponding interrupt handling vector. alternatively, tov2 is cleared by writing a logic one to the flag. when the sreg i-bit, toie2a (timer/counter2 overflow inter- rupt enable), and tov2 are set (one), the timer/counter2 overflow interrupt is executed. in pwm mode, this bit is set when timer/counter2 changes counting direction at 0x00. bit 7 6 5 4 3 2 1 0 0x17 (0x37) - - - - - ocf2b ocf2a tov2 tifr2 read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 162 tpr0327b ? vic ? 16fev11 13.4 timer/counter prescaler figure 13-36. prescaler for timer/counter2 the clock source for timer/counter2 is named clk t2s . clk t2s is by default connected to the main system i/o clock clk i o . by setting the as2 bit in assr, timer/counter2 is asynchronously clocked from the tosc1 pin. this enables use of timer/counter2 as a real time counter (rtc). when as2 is set, pins tosc1 and tosc2 are disconnected from port c. a crystal can then be connected between the tosc1 and tosc2 pins to serve as an independent clock source for timer/counter2. the oscillator is optimized for use with a 32.768 khz crystal. by set- ting the exclk bit in the assr, a 32 khz external clock can be applied. see ?assr ? asynchronous status register? on page 158 for details. for timer/counter2, the possible prescaled selections are: clk t2s /8, clk t2s /32, clk t2s /64, clk t2s /128, clk t2s /256, and clk t2s /1024. additionally, clk t2s as well as 0 (stop) may be selected. setting the psrasy bit in gtccr resets the prescaler. this allows the user to operate with a predictable prescaler. 13.4.1 gtccr ? general timer/counter control register ? bit 7 ? tsm : timer/counter synchronization mode writing the tsm bit to one activates the timer/counter synchronization mode. in this mode, the value that is written to the psrasy and psrsync bits is kept, hence keeping the correspond- ing prescaler reset signals asserted. this ensures that the corresponding timer/counters are halted and can be configured to the same value without the risk of one of them advancing during 10-bit t/c prescaler timer/counter2 clock source clk i/o clk t2s tosc1 as2 cs20 cs21 cs22 clk t2s /8 clk t2s /64 clk t2s /128 clk t2s /1024 clk t2s /256 clk t2s /32 0 psrasy clear clk t2 bit 7 6 5 4 3 2 1 0 0x23 (0x43) tsm - - - - - psrasy psrsync gtccr read/write r/w r r r r r r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
163 tpr0327b ? vic ? 16fev11 13. timers at90scr100/116/132 configuration. when the tsm bit is written to zero, the psrasy and psrsync bits are cleared by hardware, and the timer/counters start counting simultaneously. ? bit 1 ? psrasy : prescaler reset timer/counter2 when this bit is one, the timer/counter2 prescaler will be reset. this bit is normally cleared immediately by hardware. if the bit is written when timer/counter2 is operating in asynchronous mode, the bit will remain one until the presca ler has been reset. the bit will not be cleared by hardware if the tsm bit is set. refer to the description of the ?bit 7 ? tsm: timer/counter syn- chronization mode? on page 136 for a description of the timer/counter synchronization mode. ? bit 0 ? psrsync : prescaler reset timer/counter0, timer/counter1 when this bit is one, timer/counter1 and timer/counter0 prescaler will be reset. this bit is nor- mally cleared immediately by hardware, except if the tsm bit is set. note that timer/counter1 and timer/counter0 share the same prescaler and a reset of this prescaler will affect both timers.
at90scr100/116/132 164 tpr0327b ? vic ? 16fev11
165 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 14. usb device interface this section contains an overview of the usb module and the description of the registers design to interface this usb module. it also details the usb interrupt, the suspend and resume modes, the double buffering, the mode detection and the attachment procedure. this section assumes the reader of this document is comfortable with the usb specifications v2.0, available on the www.usb.org website. he may also refer to the usb register summary, located at the end of this document to have a complete overview of the registers available. see ?register summary? on page 431. 14.1 features ? usb 2.0 fullspeed compliant ? data transfer rates up to 12mbit/s ? 8 programmable endpoints bi-directionnals ? endpoint 0 for control: 64bytes ? endpoints 1 to 3 support double buffers of 64bytes each ? endpoints 4 to 7: 8 bytes each ? suspend/resume interrupts ? resume wake up capabilities ? automatic nack if usb not ready to transmit/receive ? specific usbdma connected for fast and easy copy from endpoint to ram 14.2 overview the following diagram represents the usb module that contains the necessary logic to commu- nicate via a full-speed usb port. note note in register configuration, you may see ?x? suffix at the end of some register. this value is to be changed into 0, 1, 2, 3, 4, 5, 6 and 7 according to the endpoint targeted. the usbenum is designed to target choose the endpoint to target.
at90scr100/116/132 166 tpr0327b ? vic ? 16fev11 figure 14-1. usb module diagram the usb module of the at90scr100/116/132 is made up of the following elements: ? the usb transceiver : it is the electrical and physical interface between the usb bus and the internal logic of the at90scr100/116/132. ? the usb serial interface engine : this logical part manages the nrzi coding/decoding, the bit stuffing/unstuffing, the crc generation/checking and the serial-parallel data conversion as requested by the usb specifications. ? the universal function interface : this block is the interface between the data flow and the internal dual port ram of the usb module that contains the endpoints. ? the dpram block : the dual port ram is an internal block of the usb module. it contains the seven available endpoints and can be accessed either by the sie or the ufi. it is intended to be used as a buffer between the usb bus and the internal data bus of the at90scr100/116/132. ? the usbdma controller : the direct memory access logical module allows fast data transfers from the dpram to the ram of the at90scr100/116/132. see ?usbdma controller? on page 181. usb module usb transceiver usbdm (d-) usbdp (d+) usb sie (serial interface engine) clock and suspend / resume manager xin xout usb ufi (universal function interface) usbdma controller data exchanges usb control and status, usb interrupt, ... dpram endpoint 0 endpoint 3 endpoint 2 endpoint 1 64 bytes 2x64 bytes 2x64 bytes 2x64 bytes endpoint 4 8 bytes endpoint 5 8 bytes endpoint 6 endpoint 7 8 bytes 8 bytes
167 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 the usb interface of the at90scr100/116/132 is a module supporting one usb device address with eight configurable endpoints, managed by an embedded firmware running on the 8/16-bit risc cpu. this firmware is responsib le for handling the enumeration (particularly the setup packets management), executing the suspend and resume mode entries, filling and emptying the endpoints through the usbdma controller, sending stall packets. the device is characterized by a full-speed (12mb/s) bus-powered interface supporting suspend and resume modes and fully compliant with the usb v2.0 specifications. the endpoints 1, 2 and 3 have a double-buffering capability (double dpram size). this feature is particularly suitable for bulk data transfers and is totally managed by the hardware. see ?dou- ble buffering? on page 171. in order to communicate via the usb interface, the chip operates with at 48mhz clock. the chip internally de-activates and activates its oscillator when necessary in order to be compli- ant with the power consumption of the suspend mode. 14.3 endpoints description the usb module contains eight endpoints. they are fully configurable through their correspond- ing register usbfcex (for further details, please refer to ?usbfcex - usb function control registers for endpoint x? on page 178 ). the table below indicates the size (in bytes) of each endpoint and also shows possible configu- rations for the usb device. notes: 1. can also be interrupt or isochronous, not control 2. can also be isochronous an endpoint featuring the double-buffering capability is allocated on two banks of dpram, each bank equal to the endpoint size. endpoints 1, 2 and 3 support these double buffer of 64 bytes. see ?double buffering? on page 171. the hardware is responsible for handling the internal data toggle bit for each endpoint. this mechanism guarantees data sequence synchronisa tion between data transmitter and receiver across multiple transactions. synchronisation is achieved via use of the data0 and data1 table 14-1. endpoints description endpoint number size in bytes double- buffering capability recommended data transfer type ep0 64 no control ep1 2x64 yes bulk (1) ep2 2x64 yes bulk (1) ep3 2x64 yes bulk (1) ep4 8 no control, bulk, interrupt (2) ep5 8 no control, bulk, interrupt (2) ep6 8 no control, bulk, interrupt (2) ep7 8 no control, bulk, interrupt (2)
at90scr100/116/132 168 tpr0327b ? vic ? 16fev11 pids and separate data toggle sequence bits for the data transmitter and receiver. receiver sequence bits toggle only when the receiver is able to accept data and receives an error-free data packet with the correct data pid. trans mitter sequence bits toggle only when the data transmitter receives a valid ack handshake. data toggle synchronization is not supported for isochronous transfers. 14.4 attachment procedure this procedure must be applied in order to connect the pull-up between the usb signal d+ and usbreg, thus identifying a full-speed usb device. even after reset, the pull-up is not connected. this operation must be controlled by the software in order to attach the device. we can imagine two integration scenarios for at90scr100/116/132: ? if the at90scr100/116/132 is standalone usb device smart card reader, then, connecting the usb cable into a computer, for instance, will power up the at90scr100/116/132. after chip initialization, pll running, the usb module can be enabled using usbcr.usbe bit, set attachement pull-up can also be set to make the host detect a full-speed peripheral. the host will then reset the communication, and the feuri interruption will trigger. a enumeration procedure can finally go ahead naturally. ? if the at90scr100/116/132 can be controlled by different hosts, for example by usart and usb, and if the host detection must be done dynamically, then a specific detection must be initiated. after chip power up, communication modules initialisation and pll activation, the interruption on usart and usb (in the example) must be activated. the attachement pull-up must be enabled. then, the first interruption (usbpi.feuri or usart reception) will indicate the host communication mode. please note that in this case, the d- line may be in high-z state, making the usb module consumpts until the usb module is disabled or communication is runnning. to prevent consumption issue, a resistor or 1megaohm should be place as pull-up on usb d- line. 14.5 usb interrupts the usb interrupt sources are split into two main families: ? the usb protocol interrupts (falling edge on usb reset, start of frame, resume, suspend). they are included into the usbpi register (see ?usbpi - usb protocol interrupt register? on page 174 for further details). ? the usb endpoint interrupt (endpoint0, 1, 2, 3, 4, 5, 6 and 7). they are included into the usbei register (see ?usbei - usb endpoint interrupt register? on page 175 for further details). this register only indicates which endpoint of the eight holds the source of the note note the usb hardware module integrates the attachment pull-up resistors connected between the usb d+ differential data line and the internal 3.3 v usb regulator (usbreg). note note the serial resistors required by usb certification are not embedded in the usb hardware module. they must be added externally.
169 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 interruption. the source of the interruption can then be retrieved by checking the register usbcsex corresponding to the endpoint (see ?usbcsex - usb control and status register for endpoint x? on page 176 for further details). these sources are stall sent, setup packet received, data received, data sent events. the at90scr100/116/132 has two interrupt vectors for both families. these vectors, called usb endpoint and usb protocol are only valid if the chip operates with the usb interface and are respectively located at addresses $003e and $0040. every source can be enabled/disabled through bits of usbeim or usbpim registers. the figure below shows the implications between the registers, the usb interrupt sources and the 8/16-bit risc cpu interrupt logic. for further details about the 8/16-bit risc cpu interrupt logic please refer to section 10. ?interrupts? on page 71 . figure 14-2. usb interrupt hierarchy 14.6 suspend and resume modes in order to be compliant with the usb specifications v2.0, a device has to support the low-power consumption state called suspend and its associated resumption activity called resume. the at90scr100/116/132 enters the suspend mode only when requested by the host through bus inactivity for at least 3ms. note note a usb interrupt is triggered assuming bits sreg.i is set (one) in order to enable the interrupt. ep3i ep2i ep1i ep0i usbpi usbei usbpim usbeim logical or 8/16-bit risc cpu interrupt logic usb protocol usb endpoint feuri feurim sofi sofim rmwui rmwuim resi resim susi susim ep3im ep2im ep1im ep0im ucse3 ucse3 ucse1 ucse3 ucse0 ucse2 endpoint interrupt protocol interrupt ucse4 ucse5 ucse6 ucse7 ep4i ep5i ep6i ep7i ep4im ep5im ep6im ep7im
at90scr100/116/132 170 tpr0327b ? vic ? 16fev11 the usb module is able to detect this request and automatically sets the bit usbpi.susi. see ?usbpi - usb protocol interrupt register? on page 174. this event generates a usb interruption if the suspend interrupt source is not masked and if the usb interrupt is enabled. once suspend mode has been entered, the usb module is able to detect a resume request. this event immediately and automatically makes the chip come out the power-down mode and sets (one) bit usbpi.resi. the fact that bi t usbpi.resi is set (one) triggers a new usb interrupt if the resume interrupt source is not masked and if the usb interrupt is enabled. the application software shall then clear the interrupt source in its interrupt service routine. 14.6.1 remote wake-up the usb module is also able to generate a remote wake-up signal (k signal) to raise the com- munication with the host. to enable this feature, the usbgs.rmwue bit must be set. the wake-up signal start to be generated by setting the bit usbcr.urmwu bit. as soon as this bit is set, a protocol interrupt is generated, if usbpim.rmwuim bit is set. through the raise of usbpi.rmwui flag. the remote wake-up signal will be automatically stopped after ~13ms generation. as soon as the signal stops, the usbgs.rsmon bit is cleared. below is a scheme showing all the signal for remote wake up management. note note in order to support the power consumpti on threshold fixed by the usb specifica- tions, the oscillator is switched off by hardware. the power-down mode must be entered by setting appropriate configuration in smcr and followed by a sleep instruction. note note when a resume signal has been detected the usb module does not automati- cally restarts the internal oscillator. see ?important note about: entering and leaving low consumption modes? on page 56. note note when the usbgs.rsmon bit is cleared, do not forget to clear usbcr.urmwu bit, for next remote wake up sequence.
171 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 figure 14-3. remote wake up state sequence description 14.7 double buffering this special feature available on the endpoints 1, 2 and 3 allows the user to save time during usb transfers. it is specially recommended for bulk data transfers but is also suitable for isochronous or interrupt. control is not possible on these double buffered endpoints. the double buffering uses two different data banks of the endpoint size. its management remains transparent for the user. the advantages of the double buffering are the followings: ? when receiving data from the host, the software can process the data received in one of the two banks while the second is being filled. the endpoints that do not have the double buffering capability must wait for their dpram to be emptied by the software before being ready to receive new data. ? when sending data to the host, the software can fill the free bank while the usb module is sending data from the other one. the endpoints that do not have this feature must wait for the previous data to be sent before being allowed to fill again the single bank. the two following figures provide code algorithm for sending data to the host and receiving data from the host (respectively in and out tokens). they are also valid for endpoints operating nor- mally (without the double buffering capability). usbgs.rmwue usbcr.urmwu usbgs.rmson usbpi.rmwui enable the feature... ...start the wakeup signal generation... ...and wait the end of the generation. flag to be cleared by software control to be cleared by software ~13ms
at90scr100/116/132 172 tpr0327b ? vic ? 16fev11 figure 14-4. sending data packets (single buffering) figure 14-5. receiving data packets note note the figure is correct if several data packets have to be sent. if only one packet is to be sent the testing of the bit usbcse.txpb must be ignored. fill dpram set bit usbcsex.txpb usbcsex.txpb = 0 ? yes usbcsex.txc = 1 ? (polling or interrupt) no no yes clear bit usbcsex.txc last data packet reached ? no yes end usbcsex.txpb = 0 ? yes no usbcsex.rcvd = 1 ? (polling or interrupt) no read register usbdbcex -> nbbytes read dpram to get nbbytes bytes of data clear ucsex.rcvd end
173 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 14.8 usb device registers description 14.8.1 usbcr - usb control register ? bit 7 - urmwu : usb remote wake up bit when in suspend mode, setting this bit to one generates a wake-up command to the host, according to usb2.0 specifications. this bit must be cleared by software when usbgs.rsmon is cleared. see ?remote wake-up? on page 170. ? bit 6 - res : reserved bit this bit is reserved bits in the at90scr100/116/132 and is always read as zero. ? bit 5 - upuc : usb pull-up connection bit this bit is set (one) and cleared (zero) by software. it directly acts on the connection of the usb pull-up attachment resistors between usb bus sig- nal d+ and vreg. if set (one) the pull-up is connected. if cleared (zero) the pull-up is not connected. ? bit 4..2 - res : reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bit 1 - usbe : usb enable bit you must clear this bit before using it, even if the usb module has not been used previously. set this bit to enable the usb controller. clear this bit to disable and reset the usb controller, to disable the usb transceiver and to dis- able the usb controller clock inputs. ? bit 0 - res : reserved bit this bit is reserved and will always be read as zero. bit 76543 2 10 $0000e0 urmwu - upuc - - - usbe - usbcr read/write r/w r r/w r r r r/w r initial value 0 0 0 0 0 0 0 0 0x00 note note clearing the usbe bit will freeze the usb macro the same way as prr1.prusb. anyway, these two bits are independant, and for the usb macro to run, usbe must be set and prusb must be cleared. see ?prr1 ? power reduction register 1? on page 55.
at90scr100/116/132 174 tpr0327b ? vic ? 16fev11 14.8.2 usbpi - usb protocol interrupt register the following interrupt sources are all sources for the usb protocol interruption ? bits 7..5 - res : reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bit 4 - feuri : falling edge on usb reset interrupt bit set (one) by hardware when a falling edge on the usb reset has occurred. this bit indicates the end of the usb bus reset signaling. this interruption is not maskable at the usbpim register level (see ?usbpim - usb protocol interrupt mask register? on page 174 ). cleared (zero) by software. ? bit 3 - sofi : start of frame interrupt bit set (one) by hardware when a start of frame pid has been detected on the usb bus. cleared (zero) by software. ? bit 2 - rmwui :remote wakeup interrupt bit set (one) byt hardware when the usbcr.urmwu bit is set. cleared (zero) by software. ? bit 1 - resi : resume interrupt bit set (one) by hardware when a usb resume signal has been detected on the usb bus. cleared (zero) by software. ? bit 0 - susi : suspend interrupt bit set (one) by hardware when a usb suspend signal has been detected on the usb bus. cleared (zero) by software. 14.8.3 usbpim - usb protocol interrupt mask register see ?usbpi - usb protocol interrupt register? on page 174. bit 76543 2 10 $0000e1 - - - feuri sofi rmwui resi susi usbpi 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 0x00 note note these bits can also be set (one) by software. bit 76543 2 10 $0000e2 ----sofimrmwuimresimsusimusbpim read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 1 0 0x02
175 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 ? bits 7..4 - res : reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bit 3 - sofim : start of frame interrupt mask bit when sofim is set (one) the start of frame interrupt is enabled. when sofim is cleared (zero) the start of frame interrupt is masked. ? bit 2 - rmwuim : remote wake-up interrupt mask bit when rmwuim is set (one), the remote wakeup interrupt is enabled. when rmwuim is cleared (zero), the remote wakeup interrupt is disabled. ? bit 1 - resim : resume interrupt mask bit when resim is set (one) the resume interrupt is enabled. when resim is cleared (zero) the resume interrupt is masked. ? bit 0 - susim : suspend interrupt mask bit when susim is set (one) the suspend interrupt is enabled. when susim is cleared (zero) the suspend interrupt is masked. 14.8.4 usbei - usb endpoint interrupt register the following interrupt sources are all sources for the usb endpoint interruption. ? bit n - epni : endpoint n interrupt bit (n=0..7) this bit is set (one) by hardware when an endpoint interrupt condition has occurred on the end- point n. this bit is cleared (zero) by hardware when the endpoint interrupt source has been cleared (zero) by the software (see ?usbcsex - usb control and status register for endpoint x? on page 176 ). bit 76543 2 10 $0000e3 ep7i ep6i ep5i ep4i ep3i ep2i ep1i ep0i usbei read/writerrrrr r rr initial value 0 0 0 0 0 0 0 0 0x00 note note the endpoint interrupt conditions are listed below and further detailed in ?usbc- sex - usb control and status register for endpoint x? on page 176 . they are the same for the seven endpoints ( 0 n 7): ? usbcsen.txc bit is set in bulk in, interrupt in or control mode. ? usbcsen.rcvd bit is set in bulk out, interrupt out, isochronous out or control mode. ? usbcsen.rxsetup is set in control mode. usbcsen.stsent bit is set in bulk, interrupt or control mode.
at90scr100/116/132 176 tpr0327b ? vic ? 16fev11 14.8.5 usbeim - usb endpoint interrupt mask register see ?usbei - usb endpoint interrupt register? on page 175. ? bit n - epnim : endpoint n interrupt mask bit (n=0..7) when epnim is set (one) the endpoint n interrupt is enabled. when epnim is cleared (zero) the endpoint n interrupt is masked. 14.8.6 usbenum - usb endpoint number register ? bit 7..3 - res : reserved bits these bits are reserved and are always read as zero. ? bit 2..0 - enum2..0 : endpoint number use this register to select an endpoint. the usb device registers ended by a x correspond then to this number. 14.8.7 usbcsex - usb control and status register for endpoint x set usbenum register to point to the relevant endpoint before using the usbcex register. ? bit 7 - res : reserved bit this bit is a reserved bit in the at90scr100/116/132 and is always read as zero. ? bit 6 - ierr : isochronous error bit this bit is a status bit. it is set (one) by hardware when the crc of a packet received in an isochronous transfer is incorrect or corrupted. if the crc is correct the bit is cleared (zero) by hardware. this bit is not a source for the endpoint interrupt. ? bit 5 - fstall : force stall bit this bit is a control bit. bit 76543 2 10 $0000e4 ep7im ep6im ep5im ep4im ep3im ep2im ep1im ep0im usbeim 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 0x00 bit 76543 2 10 $0000ca ----- enum [2..0] usbenum read/writerrrrrr/wr/wr/w initial value00000 0 000x00 bit 76543 2 10 $0000cb - ierr fstall txpb stsent rxsetup rcvd txc usbcsex 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 0x00
177 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 it is set (one) and cleared (zero) by software. if it is set (one) the corresponding endpoint is stalled and the host immediately receives a stall as response to the in or out tokens sent to this endpoint (see procedure on next page). if it is cleared (zero) the corresponding endpoint is not stalled. this bit is not a source for the endpoint interrupt. ? bit 4 - txpb : tx packet busy bit this bit is a control bit. it is set (one) by software and cleared (zero) by hardware. if it is cleared (zero), the dpram bank corr esponding to the endpoint is empty. it can then be filled with data to be sent. if it is set (one), the data present in the dpram bank is sent. this bit is not a source for the endpoint interrupt. ? bit 3 - stsent : stall sent bit this bit is a status bit. it is set (one) by hardware and cleared (zero) by software. if it is set (one), a stall has been sent from the corresponding endpoint to the host through the usb bus. this bit is a source for the endpoint interrupt and must be cleared to acknowledge the interruption. ? bit 2 - rxsetup : rx setup bit this bit is a status bit. it is set (one) by hardware and cleared (zero) by software. if it is set (one) and if the corresponding endpoint operates with control mode transfers, a valid setup packet has been received from the host through the usb bus. this bit is a source for the endpoint interrupt and must be cleared to acknowledge the interruption. ? bit 1 - rcvd : received data bit this bit is a status bit. it is set (one) by hardware and cleared (zero) by software. if it is set (one), the dpram of the corresponding endpoint is filled with data coming from the host through the usb bus. this bit is a source for the endpoint interrupt and must be cleared to acknowledge the interruption. ? bit 0 - txc : tx complete bit this bit is a status bit. it is set (one) by hardware and cleared (zero) by software.
at90scr100/116/132 178 tpr0327b ? vic ? 16fev11 if it is set (one), an ack handshake from the host has been received on the corresponding end- point through the usb bus. this bit is a source for the endpoint interrupt and must be cleared to acknowledge the interruption. 14.8.8 usbdbcex - usb data byte count registers for endpoint x set usbenum register to point to the relevant endpoint before using the usbdbcex register. if a packet of data has been received from the host in the corresponding endpoint through the usb bus, these registers indicate the amount of data bytes available in the dpram. the value is considered valid if the bit usbcsex.rcvd has been previously set by hardware. ? bits 7..0 - bct7..0 : bytes count bits these bits are set (one) and cleared (zero) by hardware. 14.8.9 usbfcex - usb function control registers for endpoint x set usbenum register to point to the relevant endpoint before using the usbfcex register. ? bits 7 - epe : endpoint enable bit this bit is set (one) and cleared (zero) by software. when it is set (one) the corresponding endpoint is enabled. when it is cleared (zero) the corresponding endpoint is disabled. a disabled endpoint does not respond when addressed (read or written) by the host. at usb reset, epe for endpoint 0 (usbfcex.ep e for usbenum=0) is automatically set by hardware. ? bits 6..3 - res : reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bit 2- epdir : endpoint direction bit this bit is set (one) and cleared (zero) by software. this bit indicates the direction of the endpoint and is not valid for endpoints operating in control transfer mode as this type of transfer occurs in both direction. if it is set (one), the endpoint direction is in. if it is cleared (zero), the endpoint direction is out. bit 76543 2 10 $0000cc bct7 bct6 bct5 bct4 bct3 bct2 bct1 bct0 usbdbcex 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 0x00 bit 76543 2 10 $0000cd epe----epdireptyp1eptyp0usbfcex read/writer/wrrrrr/wr/wr/w initial value 0 0 0 0 0 0 0 0 0x00
179 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 ? bits 1..0 - eptyp0 eptyp1 : endpoint type bits these bits are set (one) and cleared (zero) by software. these bit indicate the type of usb data transfer of the corresponding endpoint. see table below for the values available: 14.8.10 usbrste - usb reset endpoint register ? bits 7..0 - rste7..0 : reset endpoint 7..0 bits these bits are set (one) by software and cleared (zero) by hardware. each endpoint has its corresponding bit (e.g rste3 corresponds to the endpoint 3) which is used to reset the endpoint. when resetting an endpoint, the following actions are performed: ? reset the dpram address pointers. ? set the internal data toggle bit to zero. to reset endpoint n (n=0..7), which is neces sary when changing the device configuration and recommended when receiving a usb bus reset signaling (before starting the enumeration oper- ations), the following procedure shall be applied: 1. clear (zero) usbrste.rsten. 2. set (one) bit usbrste.rsten. 3. wait for usbrse.rsten to be cleared (zero) by hardware (polling). 14.8.11 usbgs - usb global state register ? bits 7..4 - res : reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bits 3 - rsmon : resume signal on this bit is set and cleared by hardware. table 14-1 . endpoint types selection eptyp1 eptyp0 transfer 00 control 0 1 isochronous 10 bulk 1 1 interrupt bit 76543 2 10 $0000e5 rste7 rste6 rste5 rste4 rste3 rste2 rste1 rste0 usbrste 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 0x00 bit 7 6 5 4 3 2 1 0 $0000e6 ----rsmonrmwuefcffafusbgs read/writerrrr r r/wr/wr/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 180 tpr0327b ? vic ? 16fev11 set by hardware when a resume is sent to the usb host during remote wake-up sequence. automatically cleared when the resume signal emission is halted (last ~13ms). ? bits 2 - rmwue : remote wake-up enable this bit is set and cleared by software. set this bit to enable the remote wake-up feature. ? bit 1 - fcf : function configured flag bit this bit is cleared (zero) by the hardware when a usb reset signaling is received. the software must set (one) this bit after receiving a valid set_configuration request from the host unless it is equal to zero. the software must clear (zero) this bit after receiving a valid set_configuration request from the host with a zero value. ? bit 0 - faf : function addressed flag bit this bit is cleared (zero) by the hardware when a usb reset signaling is received. the software must set (one) this bit after receiving a valid set_address request from the host. 14.8.12 usbfa - usb function address register ? bit 7 - res : reserved bit : this bit is reserved bit in the at90scr100/116/132 and is always read as zero. ? bits 6..0 - fadd6..0 : function address register 6..0 bits these bits are cleared (zero) by the hardware when a usb reset is received. the software must update these bits with the address value received during a valid set_address request. it must then set (one) the bit usbgs.faf (see ?usbgs - usb global state register? on page 179 ). bit 76543 2 10 $0000e7 - fadd6 fadd5 fadd4 fadd3 fadd2 fadd1 fadd0 usbfa read/write r r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
181 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 14.8.13 usbfn - usb frame number registers ? bits 15..13 - res: reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bit 12 - fnend : frame number end bit this bit is set (one) and cleared (zero) by hardware. this bit is set (one) when an end of packet start of frame (sof) transaction has occurred. this bit is cleared (zero) by the next detected sof. ? bit 11 - fnerr : frame number error bit this bit is set (one) and cleared (zero) by hardware. this bit is set (one) if the last frame number field received is corrupted. otherwise it is cleared (zero). ? bits 10..0 - fn10..0 : frame number bits these bits are set (one) and cleared (zero) by hardware. these bits represent the frame number value. 14.9 usbdma controller the usbdma controller, implemented on the at90scr100/116/132, is intended to be used for executing fast transfers between the ram memory and the dpram (dual port ram) which is dedicated to the usb endpoints. this feature allows the application software of the at90scr100/116/132 to manage the exchanges imposed by the usb protocol. the usbdma controller basically requires four i/o registers to run and can be configured either to send or to receive data through the usb bus. actually, its main purpose is to transfer data between the ram of the at90scr100/116/132 and the dpram of the usb module. very easy to use, it just requires the application software to select an endpoint (which can be the source or bit 1514131211 10 9 8 $0000e9 - - - fnend fnerr fn10 fn9 fn8 usbfnh $0000e8 fn7 fn6 fn5 fn4 fn3 fn2 fn1 fn0 usbfnl bit 76543 2 10 read/writerrrrr r rr rrrrr r rr initial value 0 0 0 0 0 0 0 0 0x00 00000 0 000x00 note note the frame number value represented by the eleven bits usbfnh.fn2..0 and usbfnl.fn7..0 should only be read when bit usbfnh.fnend is set (one). caution ! all the usb registers described in this section cannot be accessed if the usb module is not enabled.
at90scr100/116/132 182 tpr0327b ? vic ? 16fev11 the destination), to set a valid base address in ram (which can be the source or the destina- tion), to fix the amount of data to be exchanged and the direction of the transfer. one usbdma operation can transfer up to n bytes in (n+1) 8/16-bit risc cpu cycles. figure 14-6. usbdma controller diagram 14.9.1 usbdmacs - usbdma control and status register this is the control and status register of the usbdma controller. ? bit 7 - res : reserved bit this bit is reserved in the at90scr100/116/132 and is always read as zero. ? bit 6..4 - eps2..0 : endpoint selection bits these bits are set (one) and cleared (zero) by software. note note even if not represented above, the exchanges between the ram and the dpram are controlled by the usb usbfi (see ?usb module diagram? on page 34) . when a usbdma operation is started, the 8/16-bit risc cpu is automatically stopped. at the end of the usbdma operation, the application software automati- cally restarts where it left (actually with the instruction following the launching of the usbdma operation). thus the application software does not need to wait for an interruption or to poll the end of the usbdma operation. ram dpram $100 $10ff endpoint 0 (64 bytes) endpoint 1 (2x64 bytes) endpoint 2 (2x64 bytes) endpoint 3 (2x64 bytes) usbdmacs.eps2:0 000 001 010 011 usbdmacs.dmar 0 1 usbdmacs.dmadir 0 1 dmab usbdmacs.dmaerr dmad endpoint 4 (8 bytes) endpoint 5 (8 bytes) endpoint 6 (8 bytes) 100 101 110 endpoint 7 (8 bytes) 111 dma controller diagram bit 3 2 1 0 0000ea - eps2 eps1 eps0 - usbdmaerr usbdmair usbdmar usbdmacs 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 0x00
183 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 they are used to select the source or destination endpoint for the next usbdma operation. table 14-2. endpoint selection bits ? bit 3 - res : reserved bit this bit is reserved in the at90scr100/116/132 and is always read as zero. ? bit 2 - usbdmaerr : usb dma error bit when launching the usbdma controller, this bit is cleared (zero) by the hardware if the values into usbdmadh, usbdmadl and usbdmab registers are suitable for the usbdma operation requested. this bit can also be cleared(zero) by software. this bit is set (one) by hardware when starting a usbdma operation and whenever one of these following cases occurs: ? the base address contained in the registers usbdmadh and usbdmadl is incorrect (out of the allowed range). ? according to the values of the registers usbdmadh, usbdmadl and usbdmab and even if the base address is correct, an address out of the allowed range is going to be reached. ? the value in the register usbdmab is greater than the size of the selected endpoint for the usbdma operation (see bits usbdmacs.eps2:0 below). when this bit is set, and if the usb unterruptions are enabled, a usb interruption is generated. ? bit 1 - usbdmadir : usb dma direction bit this bit is set (one) and cleared (zero) by software. it indicates the direction of the next usbdma operation transfer between the ram memory and the selected endpoint (represented by the bits usbdmacs.eps2:0): note note a violation is triggered if a usbdma operation is launched with 0 byte to transfer or when usbmacs.eps2:0 value is more than 4. eps2 eps1 eps0 endpoint selected endpoint size (bytes) 0 0 0 endpoint 0 64 0 0 1 endpoint 1 2x64 0 1 0 endpoint 2 2x64 0 1 1 endpoint 3 2x64 1 0 0 endpoint 4 8 1 0 1 endpoint 5 8 1 1 0 endpoint 6 8 1 1 1 endpoint 7 8 caution ! don?t forget to clear the usbdmacs.dmaerr bit before leaving the interruption routine to avoid repetitive and endless interruptions.
at90scr100/116/132 184 tpr0327b ? vic ? 16fev11 ? if the bit is cleared (zero), the transfer will be from the selected endpoint to the ram memory (receiving mode). ? if the bit is set (one), the transfer will be from the ram memory to the selected endpoint (emission mode). ? bit 0 - usbdmar : usb dma run bit this bit is set (one) by software and cleared (zero) by hardware. this bit controls the usbdma operation launching. it is set (one) by software when a usbdma operation is to be performed. it is cleared (zero) by hardware at the end of the operation. 14.9.2 usbdmad - usbdma address registers ? bits 15..14 - res : reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bits 13..0 - usbdmad13..0 : dma address these bits represents the 14-bit usbdma address. these two registers set the base address in ram. this address represents the source of the data to be sent if the usbdma controller is configured in the emission mode. it represents the destination to store the data if the usbdma controller is configured in the receiving mode. the initial value corresponds to ram address $000100. note note it?s not possible to read data back previously stored in dpram. note note the software does not need to poll this bit in order to detect the end of the usb- dma operation. indeed, when the usbdmacs.dmar bit is set by the software, the 8/16-bit risc cpu is automatically stopped. when the end of the usbdma operation is reached, the 8/16-bit risc cpu then automatically executes the instructions following the setting of the bit usbdmacs.dmar. note note a usbdma operation can not be interrupted because the cpu is not available during this time. bit 15 14 13 12 11 10 9 8 $0000ec - - usbdmad [13..8] usbdmadh $0000eb usbdmad [7..0] usbdmadl bit 7 6 5 4 3 2 1 0 read/write r r 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 1 0x01 0 0 0 0 0 0 0 0 0x00
185 tpr0327b ? vic ? 16fev11 14. usb device interface at90scr100/116/132 you can address the whole ram with this parameter. values in ram that must not be dumped, shall be stored out of the usbdma ram accessible range. when starting a usbdma operation, the hardware will check if the values of usbdmadh, usb- dmadl and usbdmab registers does not exceed the specific ram area ($000100 to $0010ff). if an error is detected, usbdmacs.dmaerr bit is automatically set (one). a super- visor ram illegal access attempt violation security interrupt (if not masked) is so triggered. usbdmadh, usbdmadl and usbdmab registers keep their previous value. 14.9.3 usbdmab - usbdma amount of bytes register this register is dedicated to the amount of bytes to be transferred during the next usbdma operation setting. ? bit 7 - res : reserved bit this bit is reserved bit in the at90scr100/116/132 and is always read as zero. ? bits 6..0 - usbdmab6..0 : dma amount of bytes bits these bits are the (6..0) bits of the 7-bit usbdma amount of bytes value. when starting a usbdma operation, the hardware will check if the values of usbdmadh, usb- dmadl and usbdmab registers does not exceed the specific ram area ($000100 to $0010ff). if an error is detected, usbdmacs.dmaerr bit is automatically set (one). a super- visor ram illegal access attempt violation security interrupt (if not masked) is so triggered. usbdmadh, usbdmadl and usbdmab registers keep their previous value. note note after a usbdma operation, usbdmadh and usbdmadl are set to the last value reached in ram and incremented by one. for instance, after a 64-byte transfer started from base address $000100, usbdmad equals to $000140 (usb- dmadh = $01 and usbdmadl = $40). this feature allows to simplify registers and bits handlings when several usbdma operations are to be successively per- formed, which can be the case when getting or sending several packets. bit 76543 2 10 $0000ed - usbdmab [6..0] usbdmab read/write r r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 note note after a usbdma operation completion, the value of this register is not reset. the maximum value allowed for usbdmab depends on the endpoint selected.
at90scr100/116/132 186 tpr0327b ? vic ? 16fev11
187 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 15. smart card interface block (scib) the scib provides all signals to interface directly with a smart card. the compliance with the iso7816, emv?2000 and gsm standards has been certified. also, the whql standard can be achieved with an appropriate software. 15.1 features ? support of iso/iec 7816 ? performances: up to 3 cycles per etu, and iso clock up to 4.8mhz ? frequency up to 12mhz ? character mode ? one transmit/receive buffer ? 11 bits etu counter ? 9 bits guard time counter ? 32 bits waiting time counter ? auto character repetition on error signal detection in transmit mode ? auto error signal generation on parity error detection in receive mode ? power off sequence generation ? manual mode to drive directly the card i/o 15.2 overview all synchronous (e.g. memory card), asynchro nous and usb smart cards (e.g. microprocessor card) are supported. the component supplies the different voltages requested by the smart card. the power_on and power_off sequence is directly managed by the scib. to enable the communication on cc4/cc8 with usb smart cards, the usb host controller must be enabled. the card presence switch of the smart card connector is used to detect card insertion or card removal. in the case of card removal, the scib will automatically initiate a smart card deactiva- tion sequence. an interrupt can be generated when a card is inserted or removed. any malfunction is reported to the microcontroller (interrupt + control register). 15.3 block diagram the smart card interface block diagram is shown figure 15-1 :
at90scr100/116/132 188 tpr0327b ? vic ? 16fev11 figure 15-1. scib block diagram 15.4 definitions this paragraph introduces some of the terms used in iso 7816-3 and emv standards. please refer to the full standards for a complete list of terms. terminal and icc terminal is the reader, icc is the integrated circuit card etu elementary timing unit (bit time) t=0 character oriented half duplex protocol t=0 t=1 block oriented half duplex protocol t=1 activation: cold reset reset initiated by the terminal with vcc power-up. the card will answer with atr (see below) activation: warm reset reset initiated by the terminal with vcc already powered-up, and after a prior atr or warm reset barrel shifter scart fsm power_on power_o fsm int i/o mux etu counter guard time counter waiting time counter sci registers interrupt generator cio (out) cio (in) cclk crst cc4 (out) cc8 (out) cc4 (in) cc8 (in) vcard clk sci
189 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 de-activation deactivation by the terminal as a result of : unresponsive icc or icc removal. atr answer to reset. response from the icc to a reset initiated by the terminal f and d f = clock rate conversion factor, d = bit rate adjustment factor. etu is defined as: etu = f/(d*f) with f= card clock frequency. if f is in hertz, etu is in second. f and d are available in the atr (byte ta1 character). the default values are f=372 and d=1. guard time the time between 2 leading edges of the start bit of 2 consecutive characters is comprised of the character duration (10 etus) plus the guard time . be aware that the guard time counter and the guard time registers in the at90scr100/116/132 consider the time between 2 consecutive characters. so the equation is guard time counter = guard time + 10. in other words, the guard time is the number of stop bits between 2 characters sent in the same direction. extra guard time iso iec 7816-3 and emv introduce the extra guard time to be added to the minimum guard time. extra guard time only apply to consecutive characters sent by the terminal to the icc. the tc1 byte in the atr define the number n. for n=0 the character to character duration is 12 etus. for n=254 the character to character duration is 266. for n=255 (special case) the min- imum character to character duration is to be used : 12 for t=0 protocol and 11 for t=1 protocol. block guard time the time between the leading edges of 2 consecutive characters sent in opposit direction. iso/ iec 7816-3 and emv recommend a fixed block guard time of 22 etus. work waiting time (wwt) in t=0 protocol wwt is the interval between the leading edge of any character sent by the icc, and the leading edge of the previous character sent either by the icc or the terminal. if no char- acter is received by the terminal after wwtmax time, the terminal initiates a deactivation sequence. character waiting time (cwt) in t=1 protocol cwt is the interval between the leading edge of 2 consecutive characters sent by the icc. if the next character is not received by the terminal after cwtmax time, the termi- nal initiates a deactivation sequence. block waiting time (bwt) in t=1 protocol bwt is the interval between the leading edge of the start bit of the last character sent by the terminal that gives the right to sent to the icc, and the leading edge of the start bit of the first character sent by the icc. if the first character from the icc is not received by the terminal after bwtmax time, the terminal initiates a deactivation sequence. waiting time extention (wtx) in t=1 protocol the icc can request a waiting time extension with a s(wtx request) request. the terminal should acknowlege it. the waiting time between the leading edge of the start bit of
at90scr100/116/132 190 tpr0327b ? vic ? 16fev11 the last character sent by the terminal that gi ves the right to sent to the icc, and the leading edge of the start bit of the first character sent by the icc will be bwt*wtx etus. parity error in t=0 protocol in t=0 protocol, a terminal (respectively an icc) detecting a parity error while receiving a char- acter shall force the card io line at 0 starting at 10.5 etus, thus reducing the first guard bit by half the time. the terminal (respectively an icc) shall maintain a 0 for 1 etu min and 2 etus max (according to iso iec) or to 2 etus (according to emv). the icc (respectively a terminal) shall monitor the card io to detect this error signal then attempt to repeat the character. accord- ing to emv, following a parity error the character can be repeated one time, if parity error is detected again this procedure can be repeated 3 more times. the same character can be trans- mitted 5 times in total. iso iec7816-3 says this procedure is mandatory in atr for card supporting t=0 while emv says this procedure is mandatory for t=0 but does not apply for atr. 15.5 functional description the architecture of the smart card interface block can be detailed as follows: 15.5.1 barrel shifter the barrel shifter performs the translation between 1 bit serial data and 8-bit parallel data. the barrel function is useful for character repetition as the character is still present in the shifter at the end of the character transmission. this shifter is able to shift the data in both directions and to invert the input or output value in order to manage both direct and inverse iso7816-3 convention. coupled with the barrel shifter is a parity checker and generator. there are 2 registers connected to this barrel shifter, one for the transmission and one for the reception. they act as buffers to relieve the cpu of timing constraints. 15.5.2 scart fsm scart fsm (smart card asynchronous receiver transmitter finite state machine) is the core of the block. its purpose is to control the barrel shifter. to sequence correctly the barrel shifter for a reception or a transmission, it uses the signals issued by the different counters. one of the most important counters is the guard time counter that gives time slots corresponding to the character frame. the scart fsm is enabled only in uart mode. see ?scicr - smart card interface control register? on page 203. the transition from reception mode to the tr ansmission mode is done automatically. priority is given to the transmission. transmission refers to terminal transmission to the icc. reception refers to reception by the terminal from the icc. 15.5.3 etu counter the etu (elementary timing unit) counter controls the operating frequency of the barrel shifter. in fact, it generates the enable signal of the barrel shifter. it receives the card clock, and gener- ates the etu clock. the card clock frequency is called ?f? below. the etu counter is 11 bit wide. a special compensation mode can be activated. it accomodates situations where the etu is not an integer number of card clock (clk sci ). the compensation mode is controlled by the comp bit in scetuh register bit position 7. with comp =1 the etu of every character even bits is
191 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 reduced by 1 card clock period. as a result, the average etu is : etu_average = (etu - 0.5). one should bear in mind that the etu counter should be programmed to deliver a faster etu which will be reduced by the comp mechanism, not the other way around. this allows to reach the required precision of the character duration specified by the iso7816-3 standard. example1: f=372, d=32 => etu= f/d = 11.625 clock cycles. we select etu[10-0]= 12 and comp=1. etuaverage= 12 - (0.5*comp) = 11.5 the result will be a full character duration (10 bit) = (10 - 0.107)*etu. the emv specification is (10 +/- 0.2)*etu 15.5.4 guard time counter the minimum time between the leading edge of the start bits of 2 consecutive characters trans- mitted by the terminal is controlled by the guard time counter, as described in figure 15-4 . the guard time counter is an 9 bit counter. it is initialized to 001h at the start of a transmission by the terminal. it then increments itself at each etu until it reaches the 9 bit value loaded into the scgt register. at this time a new terminal transmission is enabled and the guard time counter stops incrementing. as soon as a new transmission starts, the guard time counter is re-initialized to 1. care must be taken with the guard time counter which counts the duration between the leading edges of 2 consecutive characters. this corres ponds to the character duration (10 etus) plus the guard time as defined by the iso and emv recommendations. to program guard time = 2 : 2 stop bits between 2 characters which is equivalent to the minimum delay of 12 etus between the leading edges of 2 consecutive characters, scgt should be loaded with the value 12 deci- mal. see figure 15-2 . figure 15-2. guard time 15.5.5 block guard time counter the block guard time counter provides a way to program a minimum time between the leading edge of the start bit of a character transmitted by the icc and the leading edge of the start bit of a character sent by the terminal. iso/iec 7816-3 and emv recommend a fixed block guard time of 22 etus. the at90scr100/116/132 offers the possibility to extend this delay up to 512 etus. the block guard time is a 9 bit counter. when the block guard time mode is enabled (bgten=1 in scsr register) the block guard time counter is initialized to 000h at the start of a note note the value of the guard time counter cannot be read. reading scgt only gives the minimum time between 2 characters that the guard time counter allows. char n+1 >= scgt char n+2 transmission to icc
at90scr100/116/132 192 tpr0327b ? vic ? 16fev11 character receptions by the icc. it then increments at each etu until it reaches the 9 bit value loaded into shadow scgt registers, or until it is re-initialized by the start of an new transmission by the icc. if the block guard time counter reaches the 9 bit value loaded into shadow scgt registers, a transmission by the terminal is enabled, and the block guard time counter stops incrementing. the block guard time counter is re-initialized at the start of each terminal transmission. the scgt shadow registers are loaded with the content of gt[8-0] contained in the registers scgt with the rising edge of the bit bgten in the scsr register. see figure 15-4 . figure 15-3. block guard time figure 15-4. guard time and block guard time counters to illustrate the use of guard time and block guard time, consider the iso/iec 7816-3 recom- mendation: guard time = 2 (minimum delay between 2 consecutive characters sent by the terminal = 12 etus) and block guard time = 22 etus. after a smart card reset ? first write ?00? decimal in scgth, then write ?22? decimal in scgtl ? set bgten in scsr (bgten was 0 before as a result of the smart card reset) ? write ?12? decimal in scgtl now the guard time and block guard time are properly initialized. the terminal will insure a minimun 12 etus between 2 leading edges of 2 consecutive characters transmitted. the termi- nal will also insure a minimum of 22 etus between the leading edge of a character sent by the char 1 >= scgt char 2 char n char 1 char 2 reception from icc transmission to icc >= block guard time write block guard time in scgt register and set the bgten to transfer the value to the shadow scgt register write scgt with a value for guard time guard time counter block guard time counter comparator comparator shadow scgth shadow scgtl scgth scgtl etu counter 9 bits transmit enable transmit enable 9 bits 9 bits gt[8..0] 9 bits
193 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 icc, and the leading edge of a character sent by the terminal. there is no need to write scgt again and again. 15.5.5.1 changing bgt and etu values according to the answer to reset or the prot ocol and parameters selection (pps, protocol t=0) received, the etu value should be changed. this etu duration modification is done after the last byte received from the card. howeve r the etu change will directly impact the block guard time that is based on etu duration. hence, a special care must be taken to keep the original etu length until the first block is trans- mitted by the terminal in spite of the etu value change. the following procedure describes the way for changing the etu and bgt values: 1. when changing the etu, bgt counter must be reloaded with a value equal to:: 2. then following transmission of the first block from terminal to the card, the bgt coun- ter should be reloaded with the correct bgt value. see figure 15-5 on page 193 for details. figure 15-5. etu change procedure 15.5.6 waiting time (wt) counter the wt counter is a 32 bits down counter which can be loaded with the value contained in the scwt3, scwt2, scwt1, scwt0 registers. its main purpose is timeout signal generation. it is 32 bits wide and is decremented at the etu rate. see figure 15-6 . when the wt counter times out, an interrupt is generated and the scib function is locked: reception and emission are disabled. it can be enabled by resetting the macro or reloading the counter. bgt 11 + () originaletu newetu ----------------------------------- bgt + >= scgt char n-1 char n char 1 char 2 reception from icc transmission to icc >= block guard time formula: (bgt-11)* + bgt original_etu new_etu 1 - change etu 2 - load bgt with calculated value 3 - reload gt 4 - send first block to icc 5 - wait block sent 6 - load correct bgt value 7 - reload gt
at90scr100/116/132 194 tpr0327b ? vic ? 16fev11 figure 15-6. waiting time counter 15.5.6.1 manual or automatic mode two modes are available to load the wt counter. according to the scicr.uart and scicr.wten bits, the wt counter will be automatically or manually loaded ? manual mode when scicr.uart bit is cleared, the counter is in manual mode and so the counter should be manually loaded. the wten signal controls the start (rising edge) and the stop of the counter (falling edge). after a timeout of the counter, wten should be cleared, scwt2 reloaded and and then wten set to start again the counter and to release the scib macro. scwt3, scwt2, scwt1 and scwt0 registers (scwt0 contains wt[7-0] bytes) are used to load the waiting time counter hold registers with a 32 bit word. in manual mode, the counter hold registers are loaded with scwt0, scwt1, scwt2, scwt3 values when scwt2 is writ- ten. please refer to figure 15-7 for more details. figure 15-7. wt counter configuration guard time counter timeout load wt [31..0] etu counter wten write scwt2 uart start bit scwt3 scwt2 scwt1 scwt0 wt counter disabled wt counter in automatic mode wt counter in manuel mode default wt value wten = 0 uart = 0 start wt counter enable automatic mode the wt counter should be manually reloaded the wt counter is automatically re-loaded at each start bit the counter is loaded when scwt2 is written write the new wt value write scwt0 write scwt1 write scwt3 write scwt2 set uart set wten
195 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 to reload the wt counter, scicr.wten bit should be cleared before writing a new value in scwt registers. then the counter will be enabled by setting scicr.wten bit. ? automatic mode if both scicr.uart and scicr.wten bits are set, the wt counter is in automatic mode. the wt counter is automatically re-loaded at each start bit detection. this automatic load is very useful for changing on-the-fly the timeout value since there is a regis- ter to hold the load value. this is the case for t=1 protocol. . the figure 15-8 on page 195 shows the sequence to follow in order to modify the wt in auto- matic mode. figure 15-8. wt change sequence note note a timeout can occur before the expected time due to resynchronization. to avoid this constraint, a short time has to be added: note note in automatic mode, the counter is automatically reloaded if a character is received before or equal to (wdt+1)*etu . below, scib function will be locked. wtcounter etu + 2 > old wt value new wt value clear uart clear wten wt counter in automotic mode wten = 1 uart = 1 the counter is loaded when scwt2 is written write the new wt value write scwt0 write scwt1 write scwt3 write scwt2 set uart set wten start wt counter enable automatic mode
at90scr100/116/132 196 tpr0327b ? vic ? 16fev11 15.5.6.2 waiting time counter use case the waiting time counter can be used in t=0 protocol for the work waiting time. it can be used in t=1 protocol for the character waiting time and for the block waiting time. in t=0 protocol the maximun interval between the start leading edge of any character sent by the icc and the start of the previous character sent by either the icc or the terminal is the max- imum work waiting time. the work waiting time shall not exceed 960*d*wi etus with d and wi parameters are returned by the field ta1 and tc2 respectively in the answer to reset (atr). this is the value the user shall write in the scwt0,1,2,3 register. this value will be reloaded in the waiting time counter every start bit. figure 15-9. t=0 mode in t=1 protocol : the maximum interval between the leading edge of the start bit of 2 consecu- tive characters sent by the icc is called maximum character waiting time (cwt). the character waiting time shall not exceed (2 cwi + 11) etus with 0 =< cwi =< 5 (character wait- ing time integer, cwi). consequently 12 etus =< cwt =< 43 etus. t=1 protocol also specify the maximum block waiting time. this is the time between the leading edge of the last character sent by the terminal giving the right to send to the icc, and the lead- ing edge of the start bit of the first character sent by the icc. the block waiting time shall not exceed {(2 bwi * 960) + 11} etus with 0 =< bwi =< 4 (block waiting time integer, bwi). conse- quently 971 etus =< bwt =< 15371 etus. in t=1 protocol, it is possible to extend the block waiting time with the waiting time extension (wtx). when selected the waiting time becomes bwt*wtx etus. the waiting time counter is 32 bit wide to accomodate this feature. it is possible to take advantage of the automatic reload of the waiting time counter with a start bit in uart mode (t=1 protocol use uart mode) . if the terminal sends a block of n charac- ters, and the icc is supposed to answer immediately after, then the following sequence can be used. while sending the (n-1)th character of the block, the terminal can write the scwt0,1,2,3 with bwimax. at the start bit of the nth character, the bwimax is loaded in the waiting time counter during the transmission of the nth character, the terminal can write scwt0,1,2,3 with the cwimax. at the start bit of the first c haracter sent by the icc, the cwimax will be loaded in the waiting time counter. char 1 char 2 > gt < wt
197 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 figure 15-10. t=1 mode 15.5.7 power-on and power-off fsm the power-on power-off finite state machine (fsm) applies the signals on the smart card in accordance with iso7816-3 standard. it drives the activation (cold reset and warm reset as well as de-activation) it also manages the exception conditions such as overcurrent (see dc/dc converter). the activation sequence (cold reset and warm reset) and deactivation sequence are managed by software. however, in certain specific cases (e.g. lost of power supply or card extraction), the deactivation sequence is automatically managed by hardware. to be able to power on the scib, the card must be present. after the detection of a card pres- ence, the terminal initiate a cold reset activation. the cold reset activation terminal procedure is as follow and the figure 15-11 . timing indica- tions are given according to iso iec 7816: ? reset= low , i/o in the receive state ? power vcc (see dc/dc converter) ? once vcc is established, apply clock at time ta ? maintain reset low until time ta+tb (tb< 400 clocks) ? monitor the i/o line for the answer to reset (atr) between 400 and 40000 clock cycles after tb ( 400 clocks < tc < 40000 clocks). figure 15-11. scib activation cold reset sequence after a card insertion char 1 char 2 char n bloc 1 transmission char 1 char 2 char n < bwt bloc n reception < cwt data undefined tb + tc ta + tb ta cio cclk crst cvcc
at90scr100/116/132 198 tpr0327b ? vic ? 16fev11 the warm reset activation terminal procedure is as follow and the figure 15-12 ? vcc active, reset = high, clk active ? terminal drives reset low at time t to initiate the warm reset. reset=0 maintained for at least 400 clocks until time td = t+te (400 clocks < te) ? terminal keeps the io line in receive state ? terminal drives reset high after at least 400 clocks at time td ? icc shall respond with an atr within 40000 clocks (tf<40000 clocks) figure 15-12. scib activation warm reset sequence the removal of the smart card will automatically start the power off sequence as described in figure 15-13 . the scib deactivation sequence after a lost of power supply is iso7816-3 compliant. the switch order of the signals is the same as in figure 15-13 but the delay between signals is ana- log and not clock dependant. figure 15-13. scib deactivation sequence after a card extraction data undefined td + tf td=t + te cio cclk crst cvcc undefined cio cclk crst cvcc
199 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 15.5.8 interrupt generator there are several sources of interruption issued by the scib. all these interrupts generate the signal: scib interruption. see ?interrupts? on page 71. figure 15-14. scib interrupt sources this signal is high level active. each of the s ources is able to activate the scib interruption which is cleared by software by clearing the corresponding bits in the smart card interrupt register. if another interrupt occurs during the read of the smart card interrupt register, the activation of the corresponding bit in the smart card interrupt register and the new scib interruption is delayed until the interrupt register is read by the microcontroller. 15.6 additional features 15.6.1 clock the clk sci input must be in the range 1 - 5 mhz according to iso 7816. the clk sci can be programmed up to 12 mhz. in this case, the timing specification of the output buffer will not be iso 7816 compliant. please refer to section ?clock system? on page 41 for the description of the input clock. the dividers values are designed to access most common frequencies of iso7816 norm. see section ?sciclk - smart card clock register? on page 213 , for the clock frequency available in output of the smart card interface. caution ! each bit of the sciir register is irrelevant while the corresponding interruption is disabled in scier register. when the interruption mode is not used, the bits of the scisr register must be used instead of the bits of the sciir register. escti scti transmission complete escri scri scib interrupt reception complete escpi scpi parity error detected escwti scwti timer on wt counter evcarder vcarderr output voltage out of range esctbi sctbi transmit buffer copied to shift register
at90scr100/116/132 200 tpr0327b ? vic ? 16fev11 15.6.2 card presence input the cpres input can generate an interrupt on card insertion or on card removal. to do so, global interrupt must be enabled and scier.cardine must be set. the cpres interrupt is generated by an event on cpres (i.e. a high or low edge depending on the setting of scicr.carddet). cpres interrupt is triggered either on card insertion or on card removal, so the card presence can be checked thanks to the scisr.cardin bit. as soon as the program executes the cpres interrupt routine, the cpres interrupt is automat- ically cleared. see ?interrupts? on page 71 for cpres interrupt vector address. an internal pull-up on card presence input c an be disconnected in order to reduce the con- sumption (scsr.cpresres). in this case, an external resistor (typically 1 m ) must be externally tied to vcc. 15.6.3 transmit / receive buffer the contents of the scibuf transmit / receive buffer is transferred or received into / from the shift register. the shift register is not accessibl e by the microcontroller. its role is to prepare the byte to be copied on the i/o pin for a transmission or in the scibuf buffer after a reception. during a character transmission process, as soon as the contents of the scibuf buffer is trans- ferred to the shift register, the sctbe bit is set in scisr register to indicate that the scibuf buffer is empty and ready to accept a new byte. this mechanism avoids to wait for the complete transmission of the previous byte before writin g a new byte in the buffer and enables to speed up the transmission. ? if the character repetition mode is not selected (bit crep=0 in scicr), as soon as the contents of the shift register is transferred to i/o pin, the sctc bit is set in scisr register to indicate that the byte has been transmitted. ? if the character repetition mode is selected (bit crep=1 in scicr) the terminal will be able to repeat characters as requested by the icc (see the parity error in t=0 protocol description in the definition paragraph above). the sctc bit in scisr register will be set after a successful transmission (no retry or no further retry requested by the icc). if the number of retries is exhausted (up to 4 retries depending on crepsel bit in scsr) and the last attempt is still unsuccessful, the sctc bit in scisr will not be set and the scpe bit in scisr register will be set instead. during a character reception process, the contents of the shift register is transferred in the sci- buf buffer. ? if the character repetition mode is not selected (bit crep=0 in scicr), as soon as the contents of the shift register is transferre d to the scibuf the scrc bit is set in scisr register to indicate that the byte has been received, and the scibuf contains a valid character ready to be read by the microcontroller. ? if the character repetition mode is selected (bit crep=1 in scicr) the terminal will be able to request repetition if the received character exhibit a parity error. up to 4 retries can be requested depending on crepsel bit in scsr. the scrc bit will be set in scisr register after a successful reception, first reception or after retry(ies). if the number of retries is note note if card presence interruption is enabled, the at90scr100/116/132 wakes up from low power mode as soon as an event on cpres is detected.
201 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 exhausted (up to 4 retries depending on crepsel bit in scsr) and the last retry is still unsuccessful, the scrc bit and the scpe bit in scisr register will be set. it will be possible to read the erroneous character. figure 15-15. character transmission diagram caution ! the sctbi, scti, scri and scpi bits have the same functions as sctbe, sctc, scrc and scpe bits. the first ones are able to generate interruptions if the interruptions are enabled in scier register while the second ones are only status bits to be used in polling mode. if the interruption mode is not used, the sta- tus bits must be used. the sctbi, scti and scri bits do not contain valid information while their respective interrupt enable bits esctbi, excti, escri are cleared. sctbe sctc scpe sctbi scti scibuf scisr register sciir register shift register scpi parity error i/o pin transmitted character parity error scier.escti scier.esctbi
at90scr100/116/132 202 tpr0327b ? vic ? 16fev11 figure 15-16. character reception diagram 15.6.4 scib reset the scicr register contains a reset bit. if set, this bit generates a reset of the scib and its reg- isters. all default values will be set into the scib registers. 15.7 sci registers access due to synchronisation between the core clock (clk core ) and the smart card interface clock (clk- sci ), some precautions have to be taken for software access. indeed a delay can occur between the cpu writing and when the data is present in the smart card interface registers. hence if the cpu writes a new data in a sci register, during a delay: ? the value read may be equal to the old one. ? using a mask to set/clear some bits may be ignored. ? reading some bits that control the output of sci pads (e.g. card c4, c8, clk, rst...) may give the value seen on the pad. after writting a data, it is recommended to check the register content until the new value is well updated. all registers that require this check will be noted in the following paragraph, ?smart card interface block registers? on page 203 . sctbe scrc scpe sctbi scri shift register scisr register sciir register scibuf scpi received character i/o pin scier.escri
203 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 15.8 smart card interface block registers 15.8.1 scicr - smart card interface control register note: 1. see ?sci registers access? on page 202. ? bit 7 ? scireset: smart card interface reset bit set this bit to reset the smart card interface. this bit acts as an active high software reset. there is no auto-deactivation of the scib when resetting the block via scireset. the software must ensure the interface is powered down pr ior to executing the reset sequence. this sequence will ensure iso compliance. clear this bit to activate the smart card in terface. the read back value becomes 0 only when the card interface is completely activated and ready. ? bit 6 ? carddet: card presence detector sense clear this bit to indicate the card presence detector is open when no card is inserted (cpres is high and will go low when a card is inserted). set this bit to indicate the card presence detector is closed when no card is inserted (cpres is low and will go high when a card is inserted). ? bit 5..4 ? vcard[1..0]: card voltage selection bit 7 6 543210 $0000ff scireset carddet vcard [1..0] uart wten crep conv scicr (1) 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 0x00 note note when clearing this bit by software, it is required to wait till this bit is cleared before using the interface. caution ! switching the value of carddet parameter can generate interruption if scier.cardinie is set. scier.cardinie must be set only when carddet bit is correctly configured. table 15-1. card voltage selection vcard1 vcard0 cvcc 00 1.8v 01 1 0 3.0v 1 1 5.0v
at90scr100/116/132 204 tpr0327b ? vic ? 16fev11 ? bit 3 ? uart: card uart selection clear this bit to use the cardio bi t to drive the card i/o (cio) pin. set this bit to use the smart card uart to drive the card i/o (cio) pin. controls also the waiting time counter as described in ?waiting time (wt) counter? on page 193 ? bit 2 ? wten: waiting time counter enable clear this bit to stop the counter and enable the load of the waiting time counter hold registers. the hold registers are loaded with scwt0, scwt1, scwt2, scwt3 values when scwt2 is written. set this bit to start the waiting time counter. the counters stop when it reaches the timeout value. if the uart bit is set, the waiting time counter automatically reloads with the hold registers whenever a start bit is sent or received. . ? bit 1 ? crep: character repetition clear this bit to disable parity error detection and indication on the card i/o pin in receive mode and to disable character repetition in transmit mode. set this bit to enable parity error indication on the card i/o pin in receive mode and to set auto- matic character repetition when a parity error is indicated in transmit mode. depending upon crepset bit is scsr register, the receiver can indicate parity error up to 4times (3 repetitions) or up to 5times (4 repetitions) after which it will raise the parity error bit note note the dcdc peripheral must be on and the sccon.cardvcc bit must be high to generate the programmed card voltage. caution ! changing vcard while dc/dc is workding and cvcc is already on could gener- ate unexpected behavior. please power_off the cvcc, and take care dc/dc is not busy before changing these bits and reapplying new voltage. see figure 16-2 on page 217 . note note it is recommended to set card i/o pin (sccon.cardio) before setting the uart bit to avoid a glitch on the line. caution ! wten must be set only when uart is cleared. else the counter will not work correctly.
205 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 scpe bit in the scisr register. if parity interrupt is enabled, the scpi bit in sciir register will be set too. alternately, the transmitter will detect icc character repetition request. after 3 or 4 unsuccessful repetitions (depending on crepsel bit in scsr register), the transmitter will raise the parity error bit scpe bit in the scisr register. if parity interrupt is enabled, the scpi bit in sciir reg- ister will be set too. ? bit 0 ? conv: iso convention clear this bit to use the direct convention: b0 bit (lsb) is sent first, the parity bit is added after b7 bit and a low level on the card i/o pin represents a?0?. set this bit to use the inverse convention: b7 bit (lsb) is sent first, the parity bit is added after b0 bit and a low level on the card i/o pin represents a?1?. 15.8.2 sccon - smart card contacts register note: 1. see ?sci registers access? on page 202. ? bit 7 ? clk: card clock selection clear this bit to use the sccon.cardclk bit to drive card clk pin. set this bit to use clk sci signal to drive the card clk pin ? bit 6 ? reserved bit this bit is reserved for future use. ? bit 5 ? cardc8: card c8 clear this bit to drive a low level on the card c8 pin (cc8 pin). set this bit to set a high level on the card c8 pin (cc8 pin). the cc8 pin can be used as a pseudo bi-directional i/o when this bit is set. vcardok=1 (scisr.4 bit) condition must be true to change the state of cc8 pin. ? bit 4 ? cardc4: card c4 clear this bit to drive a low level on the card c4 pin (cc4 pin). set this bit to set a high level on the card c4 pin (cc4 pin). note note character repetition mode is specified for t=0 protocol only and should not be used in t=1 protocol (block oriented protocol) bit 7 6 5 4 3 2 1 0 $0000fe clk - cardc8 cardc4 cardio cardclk cardrst cardvcc sccon (1) read/write r/w r r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 note note internal synchronization avoids glitches on the clk pin when switching this bit.
at90scr100/116/132 206 tpr0327b ? vic ? 16fev11 the cc4 pin can be used as a pseudo bi-directional i/o when this bit is set. vcardok=1 (scisr.4 bit) condition must be true to change the state of cc4 pin. ? bit 3 ? cardio: card i/o if uart bit is cleared in scicr register, this bit enables the use of the card io pin (cio pin) as a standard bi-directional port : ? to read from cio port pin : set cardio bit then read cardio bit to have the cio port value ? to write in cio port pin : set cardio bit to write a 1 in cio port pin , clear cardio bit to write a 0 in cio port pin. vcardok=1 (scisr.4 bit) condition must be true to change the state of cio pin. ? bit 2 ? cardclk: card clk when the clk bit is cleared in sccon register, the value of this bit is driven to the card clk pin. vcardok=1 (scisr.4 bit) condition must be true to change the state of card clk pin. ? bit 1 ? cardrst: card rst clear this bit to drive a low level on the card rst pin. set this bit to set a high level on the card rst pin. vcardok=1 (scisr.4 bit) condition must be true to change the state of card rst pin. ? bit 0 ? cardvcc: card vcc control clear this bit to deactivate the card interface and set its power-off. the other bits of sccon reg- ister have no effect while this bit is cleared. set this bit to power-on the card interface. the activation sequence should be handled by software. 15.8.3 scisr - smart card uart interface status register note: 1. see ?sci registers access? on page 202. ? bit 7 ? sctbe: uart transmit buffer empty status this bit is set by hardware when the transmit buffer is copied to the transmit shift register of the smart card uart. caution ! it is mandatory to set cio before setting uart bit. bit 7 6 5 4 3 2 1 0 $0000fd sctbe cardin - vcardok scwto sctc scrc scpe scisr (1) read/write r r r r r r/w r/w r/w initial value 1 0 0 0 0 0 0 0 0x80
207 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 it is cleared by hardware when scibuf register is written. ? bit 6 ? cardin: card presence status this bit is set by hardware if there is a card presence (debouncing filter has to be done by software). this bit is cleared by hardware if there is no card presence. if global interrupts are activated and scier.cardine is set (one), and card presence goes high, an interrupt is generated. see ?card presence input? on page 200. ? bit 5 ? res: reserved bit this bit is reserved and will always be read as ?0?. ? bit 4 ? vcardok: card voltage correct status this bit is set when the output voltage is within the voltage range specified by vcard[1:0] in scicr register. it is cleared otherwise. ? bit 3 ? scwto: waiting time counter timeout status this bit is set by hardware when the waiting time counter has expired. it is cleared by reloading the counter or by reseting the scib. ? bit 2 ? sctc: uart transmitted character status this bit is set by hardware when the smart card uart has transmitted a character. if character repetition mode is selected, this bit will be set only after a successful transmission. if the last allowed repetition is not successful, this bit will not be set. this bit must be cleared by software. ? bit 1 ? scrc: uart received character status this bit is set by hardware when the smart card uart has received a character. this bit must be cleared by software. if character repetition mode is selected, this bit will be set only after a successful reception. if the last allowed repetition is still unsuccessful, this bit will be set to let the user read the erroneous value if necessary. ? bit 0 ? scpe: character reception parity error status this bit is set when a parity error is detected on the received character. caution ! this bit can only be used if the guardtime parameter is lesser or equal to 11etu. the meaning of this bit if guardtime is higher than 11etu is not reliable; in this case, using sctc is mandatory. note note to modify the bits cardc8, card c4, cardio, cardclk and cardrst in register sccon, the bit vcarok must be equal to 1.
at90scr100/116/132 208 tpr0327b ? vic ? 16fev11 this bit must be cleared by software. if character repetition mode is selected, this bit will be set only if the icc report an error on the last allowed repetition of a terminal transmission, or if a reception parity error is found on the last allowed icc character repetition. 15.8.4 sciir - smart card uart in terrupt identification register ? bit 7 ? sctbi: uart tran smit buffer empty interrupt this bit is set by hardware when the transmit buffer is copied into the transmit shift register of the smart card uart. it generates an interrupt if esctbi bit is set in scier register otherwise this bit is irrelevant. this bit must be cleared by software. ? bit 5..6 ? res: reserved bits those bits arereserved and will always be read as ?0?. ? bit 4 ? vcarderr: card voltage error interrupt this bit is set when the output voltage goes out of the voltage range specified by vcard field. it generates an interrupt if evcarder bit is set in scier register otherwise this bit is irrelevant. this bit must be cleared by software. ? bit 3 ? scwti: waiting time counter timeout interrupt this bit is set by hardware when the waiting time counter has expired. it generates an interrupt if escwti bit is set in scier register otherwise this bit is irrelevant. this bit must be cleared by software. ? bit 2 ? scti: uart transmitted character interrupt this bit is set by hardware when the smart card uart has completed the character transmis- sion. it generates an interrupt if escti bit is set in scier register otherwise this bit is irrelevant. this bit must be cleared by software. ? bit 1 ? scri: uart rece ived character interrupt this bit is set by hardware when the smart card uart has completed the character reception. it generates an interrupt if escri bit is set in scier register otherwise this bit is irrelevant. this bit must be cleared by software. ? bit 0 ? scpi: character reception parity error interrupt this bit is set at the same time as scti or scri if a parity error is detected on the received char- acter. it generates an interrupt if escpi bit is set in scier register otherwise this bit is irrelevant. this bit must be cleared by software. bit 7 6 5 4 3 2 1 0 $0000fc sctbi - - vcarderr scwti scti scri scpi sciir read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 0x00
209 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 15.8.5 scier - smart card uart interrupt enable register note: 1. see ?sci registers access? on page 202. ? bit 7 ? esctbi: uart transmit buffer empty interrupt enable clear this bit to disable the smart card uart transmit buffer empty interrupt. set this bit to enable the smart card uart transmit buffer empty interrupt. ? bit 6 ? cardine: card in interrupt enable clear this bit to disable te smart card card presence detection interrupt generation. set this bit to enable te smart card card presence detection interrupt generation. ? bit 5 ? res: reserved bits those bits are reserved and will always be read as ?0?. ? bit 4 ? evcarder: card volt age error interrupt enable clear this bit to disable the card voltage error interrupt. set this bit to enable the card voltage error interrupt. ? bit 3 ? escwti: waiting time counter timeout interrupt enable clear this bit to disable the waiting time counter timeout interrupt. set this bit to enable the waiting time counter timeout interrupt. ? bit 2 ? escti: uart transmit ted character interrupt enable clear this bit to disable the smart ca rd uart transmitted character interrupt. set this bit to enable the smart card uart transmitted character interrupt. ? bit 1 ? escri: uart received character interrupt enable clear this bit to disable the smart card uart received character interrupt. set this bit to enable the smart card uart received character interrupt. ? bit 0 ? escpi: character reception parity error interrupt enable clear this bit to disable the smart card character reception parity error interrupt. set this bit to enable the smart card character reception parity error interrupt. bit 7 6 5 4 3 2 1 0 $0000fb esctbi cardine - evcarder escwti escti escri escpi scier (1) 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 0x00
at90scr100/116/132 210 tpr0327b ? vic ? 16fev11 15.8.6 scsr - smart card selection register note: 1. see ?sci registers access? on page 202. ? bit 7 ? reserved bit this bit is reserved for future use. ? bit 6 ? bgten: block guard time enable set this bit to select the minimum interval between the leading edge of the start bits of the last character received from the icc and the first character sent by the terminal. the transfer of gt[8-0] value to the bgt counter is done on the rising edge of the bgten. clear this bit to suppress the minimum time between reception and transmission.. ? bit 5 ? reserved bit this bit is reserved for future use. ? bit 4 ? crepsel: character repetition selection clear this bit to select 5 times transmission (1 original + 4 repetitions) before parity error indica- tion (conform to emv). set this bit to select 4 times transmission (1 original + 3 repetitions) before parity error indication. ? bit 3 ? cpresres: card presence pull-up resistor clear this bit to connect the internal 100k pull-up on cpres pin. set this bit to disconnect the internal pull-up from this pin. ? bit 2..0 ? reserved bits these bits are reserved for future use. writing these reserved bits can have side effects. take care of not writing them. 15.8.7 scibuf - smart card transmit/receive buffer ? bit 7..0 ? scibufd7..0: smar t card transmit/receive buffer bit 7 6 5 4 3 2 1 0 $0000fa - bgten - crepsel cpresres - - - scsr (1) read/write r r/w r r/w r/w r r r initial value 0 0 0 0 0 0 0 0 0x00 caution ! the scsr.bgten must not be cleared and set quickly because the macro may ignore it and the bgt counter won?t be reloaded. bit 7 6 5 4 3 2 1 0 $0000f9 scibufd [7..0] scibuf 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 0x00
211 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 a new byte can be written in the buffer to be transmitted on the i/o pin when sctbe bit is set. the bits are sorted and copied on the i/o pin according to the active convention. the register can not be read anymore as soon as sctbe is set. a new byte received from i/o pin is ready to be read when scri bit is set. the bits are sorted according to the active convention. 15.8.8 scetu - smart card etu register note: 1. see ?sci registers access? on page 202. ? bit 15 ? comp: compensation clear this bit when no time compensation is needed (i.e. when the etu to card clk period ratio is close to an integer with an error less than 1/4 of card clk period). set this bit otherwise and reduce the etu period by 1 card clk cycle for even bits. ? bit 14..11 ? reserved bits these bits are reserved for future use. ? bit 10..0 ? etu: etu value the elementary time unit is (etu[10:0] - 0.5*comp)/f, where f is the card clk frequency. according to iso 7816, etu[10:0] can be set between 11 and 2048. the default reset value of etu[10:0] is 372 (f=372, d=1). bit 1514131211 10 9 8 $0000f8 comp - - - - etu [10..8] scetuh (1) $0000f7 etu [7..0] scetul (1) bit 76543210 read/writer/wrrrrr/wr/wr/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 1 0x01 01110 1 00 0x74 note note the etu counter is reloaded at each register?s write operation. caution ! do not change this register during character reception or transmission or while guard time or waiting time counters are running.
at90scr100/116/132 212 tpr0327b ? vic ? 16fev11 15.8.9 scgt - smart card guard time register note: 1. see ?sci registers access? on page 202. ? bit 15..9 ? reserved bits these bits are reserved for future use. ? bit 8..0 ? gt8..0: transmit guard time the minimum time between two consecutive start bits in transmit mode is gt[8:0] x etu. this is equal to iso iec guard time +10. see ?block guard time counter? on page 191. according to iso iec 7816, the time between 2 consecutive leading edge start bits can be set between 11 and 266 (11 to 254+12 etus). 15.8.10 scwt - smart card character/block waiting time register note: 1. see ?sci registers access? on page 202. ? bit 31..0 ? wt: waiting time byte wt[31:0] is the reload value of the waiting time counter (wtc). the wtc is a general-purpose timer. it uses t he etu clock and is controlled by the wten bit ( see ?scicr - smart card interface control register? on page 203. and see ?waiting time (wt) counter? on page 193. ). when uart bit of ?smart card interface block registers? is set, the wtc is automatically reloaded at each start bit of the uart. it is used to check the maximum time between to consec- utive start bits. bit 1514131211 10 9 8 $0000f6 ----- - -gt8scgth (1) $0000f5 gt [7..0] scgtl (1) bit 76543210 read/writerrrrr r rr/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 0x00 00001 1 00 0x0c bit 76543210 $0000f4 wt [31..24] scwt3 (1) $0000f3 wt (23..16] scwt2 (1) $0000f2 wt [15..8] scwt1 (1) $0000f1 wt [7..0] scwt0 (1) 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 0x00 00000 0 00 0x00 00100 1 01 0x25 10000 0 00 0x80
213 tpr0327b ? vic ? 16fev11 15. smart card interface block (scib) at90scr100/116/132 15.8.11 sciclk - smart card clock register ? bit 7..6 ? reserved bits these bits are reserved for future use. ? bit 5..0 ? sciclk5..0: clock bits combination of sciclk bits provide clock divider for smart card interface output as follow: table 15-2. clock dividers for smart card interface bit 7 6 5 4 3 2 1 0 $0000f0 - - sciclk [5..0] sciclk read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 1 0 0 0x04 clk pll sciclk [5-0] scib frequency (mhz) divider 96 0x00 12 8 96 0x01 8 12 96 0x02 6 16 96 0x03 4.8 20 96 0x04 4 24 96 0x05 2 48 96 0x06 1.5 64 96 0x07 1.2 80 96 0x08 1 96 96 0x09 0.75 128 96 0x0a 0.6 160 96 0x0b 0.5 192 96 0x0c reserved reserved 96 0x0d reserved reserved 96 0x0e reserved reserved
at90scr100/116/132 214 tpr0327b ? vic ? 16fev11
215 tpr0327b ? vic ? 16fev11 16. dc/dc converter at90scr100/116/132 16. dc/dc converter 16.1 overview the at90scr100/116/132 embeds a dc/dc converter to generate voltage to supply any kind of iso7816 smart card, and to generate the vbus voltage for usb smart cards. this peripheral is also controlled by ?smart card interface block (scib)? . 16.2 features ? operating voltages : 2.7 - 5.5 v ? programmable ouput voltages : 1.8v, 3v or 5v ? automatic deactivation sequence when switched offf 16.3 description the smart card voltage (cvcc) is supplied by the integrated dc/dc converter which is con- trolled by several registers: ? the dccr register controls the start-up, shutdown of dc/dc peripheral. see ?dccr - dc/dc converter register? on page 217. ? the scicr register controls the cvcc level by means of vcard[1..0] bits. see ?scicr - smart card interface control register? on page 203. ? the sccon register controls the generation of by means of cardvcc bit. see ?sccon - smart card contacts register? on page 205. the cvcc cannot be generated while the cpres pin remains inactive. if cpres pin becomes inactive while the dc/dc converter is oper ating, an automatic power_off sequence of the dc/dc converter is initiated by the internal logic. 16.3.1 initialization procedure to generate a specific voltage on cvcc, please follow at the following diagram: caution ! to prevent any perturbation avoiding the dc/dc converter to work correctly, an rsense resistance is connected between power supply and cvsense pin. the value of this resistance depends of the resistance of the bonding wires ?smart card interface characteristics? on page 428 and the resistance of the wires. the total value of these resistances should be around 500m ohms and the rsense value is chosen in consequence, see ?application information? on page 413. note note it is mandatory to switch off the dc/dc converter before entering in power-down mode, by clearing dccr.dcon. caution ! to generate a vbus voltage to supply a usb smart card, the below process is mandatory, with scicr.vcard = b11, to generate 5v. the 3.3v of cc4/cc8 will be generate using a specific regulator.
at90scr100/116/132 216 tpr0327b ? vic ? 16fev11 figure 16-1. dc/dc initialization procedure: 16.3.2 changing vcard level parameter it is forbidden to modify the voltage delivered by cvcc while dc/dc is loaded. the dccr.dcbusy bit permits to check the state of dc/dc load. while it is set, it is advised to not: ? shut the dc/dc off (using dccr.dcon bit) ? change scicr.vcard[0..1] parameter 16.4 summary: state machine the graph below permits to see how work t he different signals of the dc/dc, and understand what is accepted, or not, regarding the moment of dc/dc use: caution ! this procedure does not take into account any error signal. this should be added for full smart card interface management. dc/dc activation cvcc generated need activation sequence wait for card insertion dccr.dcon=1 set scicr.vcard sccon.cardvcc=1 start the dc/dc converter no card presence required configure the voltage to generate no card presence required ask for cvcc generation as the dcdc voltage is now generated, the activation sequence can be processed this can be done either by polling or interruption. see card presence input section poll dc/dc converter is ready dccr.dcrdy=1? no yes poll to know when cvcc has reached the desired voltage scisr.vcardok=1 ? no yes
217 tpr0327b ? vic ? 16fev11 16. dc/dc converter at90scr100/116/132 figure 16-2. dc/dc state machine 16.5 dc/dc registers 16.5.1 dccr - dc/dc converter register ? bit 7 ? dcon : dc/dc on bit set (one) this bit to start the dc/dc up. the dc/dc must be started before trying to generate a card vcc using smart card interface. dccr.dcrdy bit will inform you when the dcdc is ready to use. clear (zero) this bit to shut the dc/dc down. ? bit 6 ? dcrdy : dc/dc ready bit this bit is cleared and set by hardware. after having started the dc/dc using dccr.dcon, this bit indicates when the dc/dc is ready to be used. this bit is cleared when the dc/dc is off. ? bit 5 ? dcbusy : dc/dc busy bit this bit is cleared and set by hardware. this bit is set when the dc/dc is loaded and running. this means that it is advised to wait for its reset before changing parameters of dc/dc, shutting dc/dc down etc... see figure 16-2 on page 217 . bit 7 6 543210 $0000ef dcon dcrdy dcbusy - - - - - dccr read/write r/w r r r r r r r initial value 0 0 0 0 0 0 0 0 0x00 internal_supply dccr.rdy dccr.busy cvcc signal dccr.dcon = 1 dccr.drdy modification of scicr.vcard ok shutdown procedure sccon.cardvcc = 1 (*): this timing depends on scicr.vcard configuration but is, at least, 20s sccon.cardvcc = 0 dccr.dcon = 0 dccr.busy ~200s >20s (*) sccon.cardvcc = 1 >20s (*) sccon.cardvcc = 0 dccr.busy modification of scicr.vcard ok
at90scr100/116/132 218 tpr0327b ? vic ? 16fev11
219 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 17. usb host controller the usb smart card interface provides an efficient way to communicate to usb with smart cards. at90scr100/116/132 embeds a usb host controller designed to communicate with usb smart card the same way as another usb host system, in addition to a usb host smart card interface, with some limitations. 17.1 features ? usb 2.0 full speed peripheral with host functions (low-speed compatbible) ? single device connection ? device load: up to 60ma ? supports usb2.0 electrical conditions ? possibility to adapt usb ic electrical conditions ? handle suspend/resume requests ? 168 bytes of dpram ? 4 pipes, configured in the dpram 17.2 usb host smart card interface description the at90scr100/116/132 usb host interface is dedicated to usb smart card connection. as a consequence, only d+/d- are controlled by this block and must be connected to c4 and c8 pads of the smart card interface pads (see smart card port in section ?pin list configuration? ). the usb host controller needs a 48mhz clock. to do so, it needs the pll running and pll mul- tiplexer switched to clk pll . see ?clock system? on page 41. finally, to be compliant with any type of usb smart card, the usb host smart card interface supports 2 different pads set: standard usb 2.0 pads (with 15k pull-down) and usb-ic pads (standard io). for usb-ic requirements, please see section ?usb-ic design? on page 220 . please refer to usb norm and documentation to get information on these two standards. finally, the at90scr100/116/132 can generate a vbus 5v using the internal dc/dc. see ?dc/dc converter? on page 215. but the card consumption will be limited, in this case, to the capabilities of dc/dc converter. anyway, the card may also be supplied by external supply volt- age with more capabilities. caution ! the usb serial resistors are not included inside usb smart card interface hardware. to be fully usb compliant, 2 externals serial resistors of 22 must be placed on d+ and d-.
at90scr100/116/132 220 tpr0327b ? vic ? 16fev11 figure 17-1. usb smart card interface block diagram 17.3 usb-ic design regarding the usb-ic specifications, the at90scr100/116/132 pads are not exactly compliant, as they do not include pull-down resistors of 30-150 k . designing a specific usb-ic system will thus require to connect 2 pull-down resistors on cc4 and cc8 pins. another external component will also be mandatory, to control the attachement of these pull- down resistors, as described in the usb-ic specifications. that is why this design will require the use of another pin to control a commutator that will attach the pull-down resistors or not. please refer to the usb-ic specification for details about the need of control. logical d+ logical d- usb smart card interface cpu internal vcc (sram) usb host controller uhcr.pad cc4 cc8 = '01' = '01' uhcr.uhen=1 scib controller usb-ic pad uhcr.pad uhcr.uhen=1 d+ d- d+ cc4 cc4 cc8 cc8 d- 15k 15k = '00' = '00' usb 2.0 clk usb on-chip usb dpram pipe 0 168 bytes pipe 1 pipe 2 pipe 3 usb regulator dc/dc
221 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 figure 17-2. usb-ic design recommendations 17.4 memory management the controller does only support the following memory allocation management: the reservation of a pipe can only be made in the growing order (pipe 0 to the last pipe). the firmware shall thus configure them in the same order. the reservation of a pipe ?k i ? is done when its alloc bit is set. then, the hardware allocates the memory and insert it between the pipe ?k i-1 ? and ?k i+1 ?. the ?k i+1 ? pipe memory ?slides? up and its data is lost. note that the ?k i+2 ? and upper pipe memory does not slide. clearing a pipe enable (pen) does not clear neither its alloc bit, nor its configuration (psize, pbk). to free its memory, the firmware should clear alloc. then, the ?k i+1 ? pipe memory auto- matically ?slides? down. note that the ?k i+2 ? and upper pipe memory does not slide. the following figure illustrates the allocation and reorganization of the usb memory in a typical example: figure 17-3. usb smart card interface block diagram at90scr100 cc4 cc8 d+ d- 30k < rpdh < 150k rpdh rpdh bidirectional commutator gpio can be any control pin 0 1 2 3 free pipe activation pen=1 alloc=1 pipe activation pipe disable free its memory (alloc=0) 0 pen=0 (alloc=1) lost memory 2 3 free 0 2 3 free 0 1 (bigger size) 2 3 free conflict
at90scr100/116/132 222 tpr0327b ? vic ? 16fev11 ? first, pipe 0 to pipe 3 are configured, in the growing order. the memory of each is reserved in the dpram. ? then, the pipe 1 is disabled (epen=0), but its memory reservation is internally kept by the controller. ? its alloc bit is cleared: the pipe 2 ?slides? down, but the pipe 3 does not ?slide?. ? finally, if the firmware chooses to reconfigure the pipe 1 with a bigger size. the controller reserved the memory after the pipe 0 memory and automatically ?slide? the pipe 2. the pipe 3 does not move and a memory conflict appears, in that both pipe 2 and 3 use a common area. the data of those pipes are potentially lost. 17.5 usb host controller description 17.5.1 pipe description for the usb host controller, the term of pipe is used instead of endpoint for the usb device controller. a host pipe corresponds to a device endpoint, as described in the usb specification: figure 17-4. pipes and endpoints in a usb system in the usb host controller, a pipe will be associated to a device endpoint, considering the device configuration descriptors. 17.5.2 power-on and reset the next diagram explains the usb host controller main states on power-on: note note ? the data of pipe/endpoint 0 are never lost whatever the activation or deactivation of the higher pipe. its data is lost if it is deactivated. ? deactivate and reactivate the same pipe with the same parameters does not lead to a ?slide? of the higher endpoints. for those endpoints, the data are preserved. ? cfgok is set by hardware even in the case that there is a ?conflict? in the memory allocation.
223 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 figure 17-5. usb sci states after reset usb host controller state after an hardware reset is ?reset?. when the usb host controller is enabled, the usb controller is in ?idle? state. in this state, the usb host controller waits for the device connection, with a minimum power consumption . the usb pad should be in idle mode. the macro does not need to have the pll activated to enter in ?host ready? state. the host controller enters in suspend state when the usb bus is in suspend state, i.e. when the host controller doesn?t generate the start of frame. in this state, the usb consumption is mini- mum. the host controller exits to the suspend state when starting to generate the sof over the usb line. 17.5.3 device detection a device is detected by the usb controller when the usb bus if different from d+ and d- low. in other words, when the usb host controller detects the device pull-up on the d+ line. to enable this detection, the host controller has to provide the vbus power supply to the device, thanks to cvcc pin. the device disconnection is detected by the usb host controller when the usb idle correspond to d+ and d- low on the usb line. 17.5.4 pipe selection prior to any operation performed by the cpu, the pipe must first be selected. this is done by: ? clearing pnums. ? setting pnum with the pipe number which will be managed by the cpu. the cpu can then access to the various pipe registers and data. host ready host idle uhcr.sofen=1 uhcr.sofen=0 device connection clock stopped macro off device disconnection device disconnection host suspend caution ! when a device disconnection event has been detected, you must reset the usb host module, to reset the internal parameters and be able to support a new connection.
at90scr100/116/132 224 tpr0327b ? vic ? 16fev11 17.5.5 pipe configuration the following flow must be respected in order to activate a pipe: figure 17-6. pipe activation flow: once the pipe is activated (upcrx.pen set), the hardware is ready to send requests to the device. when configured (upstax.cfgok=1), only the pipe token (upcfg0x.ptoken) and the polling interval for interrupt pipe can be modified. there are 4 pipes to configure. a control type pipe supports only 1 bank (or data bank). any other value will lead to a configuration error (upstax.cfgok=0). caution ! to guarantee a correct operation of the usb host controller: ? the pipe 0 size must not be greater than 32 bytes. ? the pipe 1 size must not be greater than 64 bytes. ? the pipe 2 size must not be greater than 64 bytes. ? the pipe 3 size must not be greater than 8 bytes. pipe activation pipe activated and freezed error upcrx.pen=1 update upcfg2x .intfrq (interrupt only) update: upcfg0x .ptype .ptoken .pepnum configure the polling interval for interrupt pipe upnum.pnum=x select the pipe to configure select the pipe type: configure the pipe memory: - type (control, isochronous, bulk, i - token (in, out, setup) - endpoint number update: upcfg1x .psize .pbk .cfgmem - pipesize - number of banks upstax.cfgok=1 ?
225 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 a clear of upcrx.pen will reset the configuration of the pipe. all the corresponding pipe regis- ters are reset to there reset values. please refer to ?memory management? section for more details. 17.5.6 usb reset the usb controller sends a usb reset when the firmware set the uhcr.reset bit. the uhint.rsti bit is set by hardware when the usb reset has been sent. this triggers an inter- rupt if the uhien.rste has been set. when a usb reset has been sent, all the pipe configuration and the memory allocation are reset. the general host interrupt enable register is left unchanged. if the bus was previously in suspend mode (uhcr.sofen = 0), the usb controller automati- cally switches to the resume mode (uhint.hwupi is set) and the uhcr.sofen bit is set by hardware in order to generate sof immediately after the usb reset. 17.5.7 address setup once the device has answer to the first host requests with the default address (0), the host assigns a new address to the device. the host controller has to send a usb reset to the device and perform a set address control request, with the new address to be used by the device. this control request ended, the firmware writes the new address into the uhaddr register. all following requests, on every pipes, will be performed using this new address. when the host controller sends a usb reset, the uhaddr register is reset by hardware and the following host requests will be performed using the default address (0). 17.5.8 remote wake-up detection the host controller enters in suspend mode when clearing the uhcr.sofen bit. no more start of frame is sent on the usb bus and the usb device enters in suspend mode 3ms later. the device awakes the host controller by sending an upstream resume (remote wake-up feature). the host controller detects a non-idle state on the usb bus and set the uhint.hwupi bit. if the non-idle correspond to an upstream resume (k state), the uhint.rxrsmi bit is set by hardware. the firmware has to generate a downstream resume within 1ms and for at least 20ms by setting the uhcr.resume bit. note note to initialize the communication with the usb device, the firmware has to configure the default control pipe with the following parameters: ? type: control ? token: setup ? data bank:1 ?size: 64 bytes the firmware will ask for 8 bytes of the device descriptor sending a get_descriptor request. these bytes contains the maxpacketsize of the device default control endpoint and the firmware will then re-configure the size of the default control pipe with this size parameter.
at90scr100/116/132 226 tpr0327b ? vic ? 16fev11 once the downstream resume has been generated, the uhcr.sofe bit is automatically set by hardware in order to generate sof immediately after the usb resume. 17.5.9 usb pipe reset the firmware can reset a pipe using the pipe re set register. the configuration of the pipe and the data toggle remains unchanged. only the bank management and the status bits are reset to their initial values. to completely reset a pipe, the firmware has to disable and then enable the pipe. 17.5.10 pipe data access in order to read or to write into the pipe fifo, the cpu selects the pipe number with the upnum register and performs read or write action on the updatx register. 17.5.11 control pipe management a control transaction is composed of 3 phases: ?setup ? data (in or out) ? status (out or in) the firmware has to change the token for each phase. the initial data toggle is set for the corresponding token (only for control pipe): ? setup: data0 ? out: data1 ? in: data1 (expected data toggle) 17.5.12 out pipe management the pipe must be configured and not frozen first. 17.5.12.1 ?manual? mode the upintx.txouti bit is set by hardware when the current bank becomes free. this triggers an interrupt if the upienx.txoute bit is set. the upintx.fifocon bit is set at the same time. the cpu writes into the fifo and clears the upintx.fifocon bit to allow the usb controller to send the data. if the out pipe is composed of multiple banks, this also switches to the next data bank. the upintx.txouti and upintx.fifocon bits are automatically updated by hardware regarding the status of the next bank. host ready uhcr.sofe=1 or uhint.hwupi=1 uhcr.sofen=0 host suspend note note if the firmware decides to switch to suspend mode (clear uhcr.sofen) even if a bank is ready to be sent, the usb controlle r will automatically exit from suspend mode and the bank will be sent.
227 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 figure 17-7. example of out data bank management 17.5.12.2 ?autoswitch? mode in this mode, the clear of the upintx.fifoc on bit is performed automatically by hardware each time the pipe bank is full. the firmware has to check if the next bank is empty or not before writing the next data. on upintx.txouti interrupt, the firmware fills a complete bank. a new interrupt will be generated each time the current bank becomes free. out ack data (bank 0) upintx.txouti sw sw upintx.fifocon sw sw out write data from cpu bank 0 write data from cpu bank 0 hw out out ack ack data (bank 0) data (bank 1) upintx.txouti sw sw upintx.fifocon sw sw write data from cpu bank 0 sw write data from cpu bank 1 write data from cpu bank 0 hw example with 1 out data bank example with 2 out data banks out out ack ack data (bank 0) data (bank 1) upintx.txouti sw sw upintx.fifocon sw sw write data from cpu bank 0 sw write data from cpu bank 1 write data from cpu bank 0 hw example with 2 out data banks
at90scr100/116/132 228 tpr0327b ? vic ? 16fev11 17.5.13 in pipe management 17.5.13.1 ?manual? mode when the host requires data from the device, the firmware has to determine first the in mode to use using the inmode bit: ? upcrx.inmode = 0. the upinrqx register is taken in account. the host controller will perform (upinrqx+1) in requests on the selected pipe before freezing the pipe. this mode avoids to have extra in requests on a pipe. ? upcrx.inmode = 1. the usb controller will perform infinite in request until the firmware freezes the pipe. the in request generation will start when the firmware clear the upcrx.pfreeze bit. each time the current bank is full, the upintx.rxini and the upintx.fifocon bits are set. this triggers an interrupt if the upienx.rxine bit is set. the firmware can acknowledge the usb interrupt by clearing the upintx.rxini bit. the firmware reads the data and clears the upintx.fifocon bit in order to free the current bank. if the in pipeis composed of multiple banks, clearing the upintx.fifocon bit will switch to the next bank. the rxini and fifocon bits are then updated by hardware in accordance with the status of the new bank. figure 17-8. example of in data bank management note note the pipe must be configured first. in ack data (to bank 0) upintx.rxini sw sw upintx.fifocon sw read data from cpu bank 0 read data from cpu bank 0 hw in ack data (to bank 0) hw example with 1 in data bank in ack data (to bank 0) upintx.rxini sw sw upintx.fifocon sw read data from cpu bank 0 read data from cpu bank 1 hw in ack data (to bank 1) hw example with 2 in data banks
229 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 17.5.13.2 ?autoswitch? mode in this mode, the clear of the upintx.fifoc on bit is performed automatically by hardware each time the pipe bank is empty. the firmware has to check if the next bank is empty or not before reading the next data. on upintx.rxini interrupt, the firmware reads a complete bank. a new interrupt will be generated each time the current bank contains data to read. the acknowledge of the upintx.rxini interrupt is always performed by software. 17.5.13.3 crc error (isochronous only) a crc error can occur during in stage if the usb controller detects a bad received packet. in this situation, the stalledi/crcerri interrupt is triggered. this does not prevent the rxini interrupt from being triggered. 17.6 interrupt system figure 17-9. usb host controller interrupt system hwupe uhien.6 hwupi uhint.6 hsofi uhint.5 hsofe uhien.5 rxrsmi uhint.4 rxrsme uhien.4 rsmedi uhint.3 rsmede uhien.3 rsti uhint.2 rste uhien.2 ddisci uhint.1 ddisce uhien.1 dconni uhint.0 dconne uhien.0 usb host interrupt
at90scr100/116/132 230 tpr0327b ? vic ? 16fev11 figure 17-10. usb host controller pipe interrupt system 17.6.1 idle and power-down the cpu exits from idle and power-down mode with any usb interrupts. 17.7 usb host controller registers 17.7.1 uhcr - usb host control register ? bit 7 - uhen : usb host enable set this bit to enable the usb host controller. this will connect cc4 and cc8 to usb host block output signals. clear this bit to disable usb host contro ller and reconnect cc4 and cc8 pads to standard smartcard interface block pads. ? bit 6..5 - pad1..0 : pad type these bits switch the d+/d- of the usb host controller outputs to specific pads as follow: ? 00 : pad electrically compliant to usb 2.0 (usb host pads) ? 01 : pad electrically compliant to usb-ic (scib pads) ? others : reserved for future use flerre upien.7 underfi upstax.5 overfi upstax.6 nakedi upintx.6 nakede upien.6 perri upintx.4 perre upien.4 txstpi upintx.3 txstpe upien.3 txouti upintx.2 txoute upien.2 rxstalli upintx.1 rxstalle upien.1 rxini upintx.0 rxine upien.0 flerre upien.7 pipe 0 pipe 1 pipe 2 pipe 3 usb host pipe interrupt bit 76543210 $009e uhen pad [1..0] frzclk - resume reset sofen uhcr read/write r/w r/w r/w r/w r r/w r/w r/w initial value 0 0 0 1 0 0 0 0 0x00
231 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 ? bits 4 - frzclk : freeze usb clock bit set to disable the pll clock input (the ?resume detection? is still active). this reduces the power consumption. clear to enable the clock inputs. ? bit 3 - res : reserved bit this bit is a reserved bit. the value read from this bit is always 0. do not set this bit. ? bit 2 - resume : send usb resume set this bit to generate a usb resume on the usb bus. cleared by hardware when the usb resume has been sent. clearing by software has no effect. ? bit 1 - reset : send usb reset set this bit to generate a usb reset on the usb bus. cleared by hardware when the usb reset has been sent. clearing by software has no effect. refer to the ?usb reset? section for more details. ? bit 0 - sofen : start of frame generation enable set this bit to generate sof on the usb bus. clear this bit to disable the sof generation and to leave the usb bus in idle state. 17.7.2 uhsr - usb host status register ? bits 7..4 - res : reserved bits these bits are reserved bits. the value read from these bits is always 0. do not set these bits. ? bit 3 - speed : speed status flag set by hardware when the controller is in full-speed mode. cleared by hardware when the controller is in low-speed mode. ? bit 2..0 - res : reserved bits these bits are reserved bits. the value read from these bits is always 0. do not set these bits. note note this bit is different from prr1.prusbh which avoid providing clock to the state machine of usb host controller, disabling the whole controller. bit 76543 2 10 $0099 ---- speed - - - uhsr read/writerrrrr r rr initial value 0 0 0 0 1 0 0 0 0x08
at90scr100/116/132 232 tpr0327b ? vic ? 16fev11 17.7.3 uhint - usb host interrupt register ? bit 7 - res : reserved bit this bit is reserved for future use. the value read from these bits is always 0. do not set these bits. ? bit 6 - hwupi : host wake-up interrupt set by hardware when a non-idle state is detected on the usb bus. shall be clear by software to acknowledge the interrupt. setting by software has no effect. ? bit 5 - hsofi : host start of frame interrupt set by hardware when a sof is issued by the host controller. this triggers a usb interrupt when hsofe is set. shall be cleared by software to acknowledge the interrupt. setting by software has no effect. ? bit 4 - rxrsmi : upstream resume received interrupt set by hardware when an upstream resume has been received from the device. shall be cleared by software. setting by software has no effect. ? bit 3 - rsmedi : downstre am resume sent interrupt set by hardware when a downstream resume has been sent to the device. shall be cleared by software. setting by software has no effect. ? bit 2 - rsti : usb reset sent interrupt set by hardware when a usb reset has been sent to the device. shall be cleared by software. setting by software has no effect. ? bit 1 - ddisci :device disconnection interrupt set by hardware when the device has been removed from the usb bus. shall be cleared by software. setting by software has no effect. after having detected a disconnecti on, please reset the usb host. see ?device detection? on page 223. ? bit 0 - dconni : device connection interrupt set by hardware when a new device has been connected to the usb bus. shall be cleared by software. setting by software has no effect. bit 76543 2 10 $009f - hwupi hsofi rxrsmi rsmedi rsti ddisci dconni uhint read/write r r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
233 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 17.7.4 uhien - usb host interrupt enable register ? bit 7 - res : reserved bit this bit is reserved for future use. the value read from these bits is always 0. do not set these bits. ? bit 6 - hwupe : host wake-up interrupt enable set this bit to enable hwup interrupt. clear this bit to disable hwup interrupt. ? bit 5 - hsofe : host start of frame interrupt enable set this bit to enable hsof interrupt. clear this bit to disable hsof interrupt. ? bit 4 - rxrsme : upstream resume received interrupt enable set this bit to enable the rxrsmi interrupt. clear this bit to disable the rxrsmi interrupt. ? bit 3 - rsmede : downstream resume sent interrupt enable set this bit to enable the rsmedi interrupt. clear this bit to disable the rsmedi interrupt. ? bit 2 - rste : usb reset sent interrupt enable set this bit to enable the rsti interrupt. clear this bit to disable the rsti interrupt. ? bit 1 - ddisce : device disconnection interrupt enable set this bit to enable the ddisci interrupt. clear this bit to disable the ddisci interrupt. after having detected a disconnecti on, please reset the usb host. see ?device detection? on page 223. ? bit 0 - dconne : device connection interrupt enable set this bit to enable the dconni interrupt. clear this bit to disable the dconni interrupt. bit 765 4321 0 $00a0 - hwupe hsofe rxrsme rsmede rste ddisce dconne uhien read/write r r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 234 tpr0327b ? vic ? 16fev11 17.7.5 uhaddr - usb host address register ? bit 7 - res : reserved bit this bit is reserved for future use. the value read from this bit is always 0. do not set this bit. ? bits 6..0 - haddr6..0 : usb host address these bits contains the address of the usb device. 17.7.6 uhfnum - usb host frame number registers ? bits 15..11 - res : reserved bits these bits are reserved for future use. the value read from these bits is always 0. do not set these bits. ? bits 10..0 - fnum10..0 - frame number the value contained in tis register is the current sof number. this value can be modified by software. 17.7.7 uhflen - usb host frame length register ? bits 7..0 - flen7..0 : frame length the value contained the data frame length transmitted bit 76543 2 10 $00a1 - haddr [6..0] uhaddr read/write r r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 1514131211 10 9 8 $00a3 ----- fnum [10..8] uhfnumh $00a2 fnum [7..0] uhfnuml bit 76543 2 10 read/writerrrrr r rr rrrrr r rr initial value00000 0 000x00 00000 0 000x00 bit 76543 2 10 $00a4 flen [7..0] uhflen read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 0x00
235 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 17.7.8 upnum - usb pipe number register ? bits 7..2 - res : reserved bits the value read from these bits is always 0. do not set these bits. ? bits 1..0 - pnum1..0 : pipe number select the pipe using this register. the usb host registers ended by a x correspond then to this number. this number is used for the usb controller following the value of the pnumd bit. 17.7.9 uprst - usb pipe reset register ? bits 7..4 - res : reserved bits the value read from these bits is always 0. do not set these bits. ? bit 3 - p3rst : pipe 3 reset set this bit to 1 and reset this bit to 0 to reset the pipe 3. ? bit 2 - p2rst : pipe 2 reset set this bit to 1 and reset this bit to 0 to reset the pipe 2. ? bit 1 - p1rst : pipe 1 reset set this bit to 1 and reset this bit to 0 to reset the pipe 1. ? bit 0 - p0rst : pipe 0 reset set this bit to 1 and reset this bit to 0 to reset the pipe 0. 17.7.10 upcrx - usb pipe control register for pipe x set upnum register to point to the relevant pipe before updating the upcrx register. ? bit 7 - res : reserved this bit is reserved. the value read from these bits is always 0. do not set these bits. ? bit 6 - pfreeze : pipe freeze bit 76543 2 10 $00a7 - pnum1 pnum0 upnum read/writerrrrr rr/wr/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 $00a8 ----p3rstp2rstp1rstp0rstuprst read/writerrrrr/wr/wr/wr/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543210 $00a9 - pfreeze inmode - rstdt - - pen upcrx read/write r r/w r/w r r/w r r r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 236 tpr0327b ? vic ? 16fev11 set this bit to freeze the pipe requests generation. clear this bit to enable the pipe request generation. this bit is set by hardware when: ? the pipe is not configured ? a stall handshake has been received on this pipe ? an error occurs on the pipe (perr = 1) ? (inrq+1) in requests have been processed this bit is set at 1 by hardware after a pipe reset or a pipe enable. ? bit 5 - inmode : in request mode set this bit to allow the usb controller to perform infinite in requests when the pipe is not frozen. clear this bit to perform a pre-defined number of in requests. this number is stored in the uin- rqx register. ? bit 4 - res : reserved bit this bit is reserved. the value read from these bits is always 0. do not set these bits. ? bit 3 - rstdt : reset data toggle set this bit to reset the data toggle to its initial value for the current pipe. cleared by hardware when proceed. clearing by software has no effect. ? bits 2..1 -res : reserved bits the value read from these bits is always 0. do not set these bits. ? bit 0 - pen : pipe enable set to enable the pipe. clear to disable and reset the pipe. 17.7.11 upcfg0x - usb pipe configuration register 0 for pipe x set upnum register to point to the relevant pipe before updating the upcfg0x register. ? bits 7..6 - ptype1..0 : pipe type select the type of the pipe: ? 00: control ? 01: isochronous ? 10: bulk ? 11: interrupt ? bits 5..4 - ptoken1..0 : pipe token select the token to associate to the pipe bit 76543210 $00aa ptype [1..0] ptoken [1..0] pepnum [3..0] upcfg0x 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 0x00
237 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 ? 00: setup ? 01: in ? 10: out ? 11: reserved ? bits 3..0 - pepnum3..0 : pipe endpoint number set this field according to the pipe configuration. set the number of the endpoint targeted by the pipe. this value is from 0 and 15. 17.7.12 upcfg1x - usb pipe configuration register 1 for pipe x set upnum register to point to the relevant pipe before updating the upcfg1x register. ? bit 7 - res : reserved this bit is reserved. the value read from these bits is always 0. do not set these bits. ? bits 6..4 - psize0..2 : pipe size select the size of the pipe: ? 000: 8 ? 001: 16 ? 010: 32 ?011: 64 ? other: reserved ? bits 3..2 - pbk0..1 : pipe bank select the number of banks to declare for the current pipe! ? 00: 1bank ? 01: 2banks ? others: reserved ? bit 1 - alloc : configure pipe memory set to configure the pipe memory with the characteristics. clear to update the memory allocation. refer to the ?memory management? chapter for more details. ? bit 0 - res : reserved this bit is reserved. the value read from these bits is always 0. do not set these bits. bit 76543210 $00ab - psize [0..2] pbk [0..1] alloc upcfg1x read/write r r/w r/w r/w r/w r/w r/w r initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 238 tpr0327b ? vic ? 16fev11 17.7.13 upcfg2x - usb pipe configuration register 2 for pipe x set upnum register to point to the relevant pipe before updating the upcfg2x register. ? bits 7..0 - intfrq7..0 : interrupt pipe request frequency these bits are the maximum value in millisecond of the pulling period for an interrupt pipe. 17.7.14 upstax - usb pipe status register for pipe x set upnum register to point to the relevant pipe before using the upstax register. ? bit 7 - cfgok : configure pipe memory ok set by hardware if the required memory configuration has been successfully performed. cleared by hardware when the pipe is disabled. the usb reset and the reset pipe have no effect on the configuration of the pipe. ? bit 6 - overfi : overflow set by hardware when a the current pipe has received more data than the maximum length of the current pipe. an interrupt is triggered if the flerre bit is set. shall be cleared by software. setting by software has no effect. ? bit 5 - underfi : underflow set by hardware when a transaction underflow occurs in the current isochronous or interrupt pipe. the pipe can?t send the data flow required by the device. a zlp will be sent instead. an interrupt is triggered if the flerre bit is set. shall be cleared by software. setting by software has no effect. ? bit 4 - res : reserved the value read from these bits is always 0. do not set these bits. ? bits 3..2 - dtseq1..0 : toggle sequencing flag bit 76543210 $00ad intfrq [7..0] upcfg2x 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 0x00 note note this value has no effect for a non-interrupt pipe. bit 76543210 $00ac cfgok overfi underfi - dtseq [1..0] nbusybk [1..0] upstax read/write r r/w r/w r r r r r initial value 0 0 0 0 0 0 0 0 0x00 note note the host controller has to send a out packet, but the bank is empty. a zlp will be sent and the underfi bit is set underflow for interrupt pipe.
239 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 set by hardware to indicate the pid data of the current bank: ? 00: data0 ? 01: data1 ? 1x: reserved. for out pipe, this value indicates the next data toggle that will be sent. this is not relative to the current bank. for in pipe, this value indicates the last data toggle received on the current bank. ? bit 0..1 - nbusybk0..1 : busy bank flag set by hardware to indicate that the number of busy banks. for out pipe, it indicates the number of busy bank(s), filled by the user, ready for out transfer. for in pipe, it indicates the number of busy bank(s) filled by in transaction from the device. ? 00: all banks are free ? 01: 1 busy bank ? 10: 2 busy banks ?11: reserved 17.7.15 upinrqx - usb pipe in request register for pipe x set upnum register to point to the relevant pipe before using the upinrqx register. ? bits 7..0 - inrq7..0 : in request number before freeze enter the number of in transactions before the usb controller freezes the pipe. the usb con- troller will perform (inrq+1) in requests before to freeze the pipe. this counter is automatically decreased by 1 each time a in request has been successfully performed. 17.7.16 uperrx - usb pipe error register for pipe x set upnum register to point to the relevant pipe before using the uperrx register. ? bit 7 - res : reserved the value read from these bits is always 0. do not set these bits. ? bits 6..5 - counter1..0 : error counter this counter is increased by the usb controller each time an error occurs on the pipe. when this value reaches 3, the pipe is automatically frozen. clear these bits by software. bit 76543210 $00a5 inrq [7..0] upinrqx 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 0x00 bit 7 6 5 4 3 2 1 0 $009d counter [1..0] crc16 ptimeout pid datapid datatgl uperrx read/write r r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 240 tpr0327b ? vic ? 16fev11 ? bit 4 - crc16 : crc16 error set by hardware when a crc16 error has been detected. shall be cleared by software. setting by software has no effect. ? bit 3 - ptimeout - pipe time-out error set by hardware when a time-out error has been detected. shall be cleared by software. setting by software has no effect. ? bit 2 - pid - pid error set by hardware when a pid error has been detected. shall be cleared by software. setting by software has no effect. ? bit 1 - datapid - data pid error set by hardware when a data pid error has been detected. shall be cleared by software. setting by software has no effect. ? bit 0 - datatgl - bad data toggle set by hardware when a data toggle error has been detected. shall be cleared by software. setting by software has no effect. 17.7.17 upintx - usb pipe interrupt register for pipe x set upnum register to point to the relevant pipe before using the upintx register. ? bit 7 - fifocon : fifo control for out and setup pipe: set by hardware when the current bank is free, at the same time than txout or txstp. clear to send the fifo data. setting by software has no effect. for in pipe: set by hardware when a new in message is stored in the current bank, at the same time than rxin. clear to free the current bank and to switch to the following bank. setting by software has no effect. ? bit 6 - nakedi : nak handshake received set by hardware when a nak has been received on the current bank of the pipe. this triggers an interrupt if the nakede bit is set in the upienx register. shall be clear to handshake the interrupt. setting by software has no effect. ? bit 5 - rwal : read/write allowed out pipe: bit 7 6 5 4 3 2 1 0 $00a6 fifocon nakedi rwal perri txstpi txouti rxstalli rxini upintx 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 0x00
241 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 set by hardware when the firmware can write a new data into the pipe fifo. cleared by hardware when the current pipe fifo is full. in pipe: set by hardware when the firmware can read a new data into the pipe fifo. cleared by hardware when the current pipe fifo is empty. this bit is also cleared by hardware when the rxstall or the perr bit is set ? bit 4 - perri : pipe error set by hardware when an error occurs on the current bank of the pipe. this triggers an interrupt if the perre bit is set in the upienx register. refers to the uperrx register to determine the source of the error. automatically cleared by hardware when the error source bit is cleared. ? bit 3 - txstpi : setup bank ready set by hardware when the current setup bank is free and can be filled. this triggers an inter- rupt if the txstpe bit is set in the upienx register. shall be cleared to handshake the interrupt. setting by software has no effect. ? bit 2 - txouti : out bank ready set by hardware when the current out bank is free and can be filled. this triggers an interrupt if the txoute bit is set in the upienx register. shall be cleared to handshake the interrupt. setting by software has no effect. ? bit 1 - rxstalli / crcerr : stall received / isochronous crc error set by hardware when a stall handshake has been received on the current bank of the pipe. the pipe is automatically frozen. this triggers an interrupt if the rxstalle bit is set in the upi- enx register. shall be cleared to handshake the interrupt. setting by software has no effect. for isochronous pipe: set by hardware when a crc error occurs on the current bank of the pipe. this triggers an inter- rupt if the txstpe bit is set in the upienx register. shall be cleared to handshake the interrupt. setting by software has no effect. ? bit 0 - rxini : in data received set by hardware when a new usb message is stored in the current bank of the pipe. this trig- gers an interrupt if the rxine bit is set in the upienx register. shall be cleared to handshake the interrupt. setting by software has no effect.
at90scr100/116/132 242 tpr0327b ? vic ? 16fev11 17.7.18 upienx - usb pipe interrupt enable register for pipe x set upnum register to point to the relevant pipe before using the upienx register. ? bit 7 - flerre : flow error interrupt enable set to enable the overfi and underfi interrupts. clear to disable the overfi and underfi interrupts. ? bit 6 - nakede : nak handshake received interrupt enable set to enable the nakedi interrupt. clear to disable the nakedi interrupt. ? bit 5 - res : reserved the value read from these bits is always 0. do not set these bits. ? bit 4 - perre : pipe error interrupt enable set to enable the perri interrupt. clear to disable the perri interrupt. ? bit 3 - txstpe : setup bank ready interrupt enable set to enable the txstpi interrupt. clear to disable the txstpi interrupt. ? bit 2 - txoute : out bank ready interrupt enable set to enable the txouti interrupt. clear to disable the txouti interrupt. ? bit 1 - rxstalle : stall received interrupt enable set to enable the rxstalli interrupt. clear to disable the rxstalli interrupt. ? bit 0 - rxine : in data received interrupt enable set to enable the rxini interrupt. clear to disable the rxini interrupt. 17.7.19 updatx - usb pipe data register for pipe x set upnum register to point to the relevant pipe before using the updatx register. bit 7 6 5 4 3 2 1 0 $00ae flerre nakede - perre txstpe txoute rxstalle rxine upienx 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 0x00 bit 7 6 5 4 3 2 1 0 $00af pdat [7..0] updatx 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 0x00
243 tpr0327b ? vic ? 16fev11 17. usb host controller at90scr100/116/132 ? bits 7..0 - pdat7..0 : pipe data bits set by the software to read/write a byte from/to the pipe fifo selected by pnum. 17.7.20 upbcx - usb pipe byte count register for pipe x set upnum register to point to the relevant pipe before using the upbcxh and upbcxl registers. ? bits 15..11 - res : reserved the value read from these bits is always 0. do not set these bits. ? bits 10..0 - pbyct10..0 : byte count bits set by hardware. pbyct10:0 is: ? (for out pipe) increased after each writing into the pipe and decremented after each byte sent, ? (for in pipe) increased after each byte received by the host, and decremented after each byte read by the software. 17.7.21 upint - usb pipe interrupt register ? bits 7..4 - res : reserved the value read from these bits is always 0. do not set these bits. ? bits 3..0 - pint3..0 : pipe interrupts bits set by hardware when an interrupt is triggered by the upintx register and if the corresponding endpoint interrupt enable bit is set. cleared by hardware when the interrupt source is served. bit 1514131211 10 9 8 $009c ----- pbytct [10..8] upbcxh $009b pbytct [7..0] upbcxl bit 76543 2 10 read/writerrrrrr/wr/wr/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 0x00 00000 0 000x00 bit 7 6 5 4 3 2 1 0 $009a - - - - pint3 pint2 pint1 pint0 upint read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 244 tpr0327b ? vic ? 16fev11
245 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 18. usart the universal synchronous and asynchronous serial receiver and transmitter (usart) is a highly flexible serial communication device. 18.1 features ? full duplex operation (independent serial receive and transmit registers) ? asynchronous or synchronous operation ? master or slave clocked synchronous operation ? high resolution baud rate generator ? supports serial frames with 5, 6, 7, 8, or 9 data bits and 1 or 2 stop bits ? odd or even parity generation and parity check supported by hardware ? data overrun detection ? framing error detection ? noise filtering includes false start bit detection and digital low pass filter ? three separate interrupts on tx complete, tx data register empty and rx complete ? multi-processor communication mode ? double speed asynchronous communication mode 18.2 usart0 the at90scr100/116/132 has one usart, usart0. 18.3 overview a simplified block diagram of the usart transmitter is shown in figure 18-1 on page 246 . cpu accessible i/o registers and i/o pins are shown in bold. the power reducion in usart0 must be disabled by writing a logical zero to prusart0 bit in prr0 register.
at90scr100/116/132 246 tpr0327b ? vic ? 16fev11 figure 18-1. usart block diagram the dashed boxes in the block diagram separate the three main parts of the usart (listed from the top): clock generator, transmitter and receiver. control registers are shared by all units. the clock generation logic consists of synchronization logic for external clock input used by synchronous slave operation, and the baud rate generator. the xck (transfer clock) pin is only used by synchronous transfer mode. the transmitter consists of a single write buffer, a serial shift register, parity generator and control logic for handling different serial frame formats. the write buffer allows a continuous transfer of data without any delay between frames. the receiver is the most complex part of the usart module due to its clock and data recovery units. the recovery units are used for asynchronous data reception. in addition to the recovery units, the receiver includes a parity checker, control logic, a shift register and a two level receive buffer (udr0). the receiver supports the same frame formats as the transmitter, and can detect frame error, data overrun and parity errors. 18.4 clock generation the clock generation logic gener ates the base clock for the transmitter and receiver. the usart0 supports four modes of clock operat ion: normal asynchronous, double speed asyn- chronous, master synchronous and slave synchronous mode. the umsel0 bit in usart parity generator ubrr[h:l] udr (transmit) ucsra ucsrb ucsrc baud rate generator transmit shift register receive shift register rxd txd pin control udr (receive) pin control xck data recovery clock recovery pin control tx control rx control parity checker data bus osc sync logic clock generator transmitter receiver
247 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 control and status register c (ucsr0c) selects between asynchronous and synchronous operation. double speed (asynchronous mode only) is controlled by the u2x0 found in the ucsr0a register. when using synchronous mode (umsel0 = 1), the data direction register for the xck pin (ddr_xck) controls whether t he clock source is internal (master mode) or external (slave mode). the xck pin is only active when using synchronous mode. figure 18-2. clock generation logic, block diagram signal description: txclk transmitter clock (internal signal). rxclk receiver base clock (internal signal). xcki input from xck pin (internal signal). used for synchronous slave operation. xcko clock output to xck pin (internal signal). used for synchronous master operation. f osc uart block clock: clk io 18.4.1 internal clock generation ? the baud rate generator internal clock generation is used for the asynchronous and the synchronous master modes of operation. the description in this section refers to figure 18-2 . the usart baud rate register (ubrr0) and the down-counter connected to it function as a programmable prescaler or baud rate generator. the down-counter, running at system clock (f osc ), is loaded with the ubrr0 value each time the counter has counted down to zero or when the ubrrl0 register is written. a clock is generated each time the counter reaches zero. this clock is the baud rate generator clock output (= f osc /(ubrr0+1)). the transmitter divides the baud rate generator clock output by 2, 8 or 16 depending on mode. the baud rate generator out- put is used directly by the receiver?s clock and data recovery units. however, the recovery units use a state machine that uses 2, 8 or 16 states depending on mode set by the state of the umsel0, u2x0 and ddr_xck bits. prescaling down-counter /2 ubrr /4 /2 fosc ubrr+1 sync register clk or xck xck pin txclk u2x umsel ddr_xck 0 1 0 1 xcki io xcko d dr_xck rxclk 0 1 1 0 edge detector ucpol
at90scr100/116/132 248 tpr0327b ? vic ? 16fev11 table 18-1 contains equations for calculating the baud rate (in bits per second) and for calculat- ing the ubrr0 value for each mode of operation using an internally generated clock source. some examples of ubrr0 values for some system clock frequencies are found in table 18-9 on page 268 . 18.4.2 double speed operation (u2x0) the transfer rate can be doubled by setting the u2 x0 bit in ucsr0a. setting this bit only has effect for the asynchronous operation. set this bit to zero when using synchronous operation. setting this bit will reduce the divisor of the baud rate divider from 16 to 8, effectively doubling the transfer rate for asynchronous communication. note however that the receiver will in this case only use half the number of samples (reduced from 16 to 8) for data sampling and clock recovery, and therefore a more accurate baud rate setting and system clock are required when this mode is used. for the transmitter, there are no downsides. table 18-1. equations for calculating baud rate register setting operating mode equation for calculating baud rate (1) 1. the baud rate is defined to be the transfer rate in bit per second (bps) baud baud rate (in bits per second, bps) f osc system oscillator clock frequency injected in uart block: clk io ubrrn contents of the ubrrh0 and ubrrl0 registers, (0-4095) equation for calculating ubrr value asynchronous normal mode (u2x0 = 0) asynchronous double speed mode (u2x0 = 1) synchronous master mode baud f osc 16 ubrr 01 + () ------------------------------------------ = ubrr 0 f osc 16 baud ----------------------- - 1 ? = baud f osc 8 ubrr 01 + () -------------------------------------- - = ubrr 0 f osc 8 baud -------------------- 1 ? = baud f osc 2 ubrr 01 + () -------------------------------------- - = ubrr 0 f osc 2 baud -------------------- 1 ? =
249 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 18.4.3 external clock external clocking is used by the synchronous slave modes of operation. the description in this section refers to figure 18-2 for details. external clock input from the xck pin is sampled by a synchronization register to minimize the chance of meta-stability. the output from the syn chronization register mu st then pass through an edge detector before it can be used by t he transmitter and receiver. this process intro- duces a two cpu clock period delay and therefore the maximum external xck clock frequency is limited by the following equation: 18.4.4 synchronous clock operation when synchronous mode is used (umsel0 = 1), the xck pin will be used as either clock input (slave) or clock output (master). the dependency between the clock edges and data sampling or data change is the same. the basic principle is that data input (on rxd0) is sampled at the opposite xck clock edge of the edge the data output (txd0) is changed. figure 18-3. synchronous mode xck timing. the ucpol0 bit ucrsc selects which xck clock edge is used for data sampling and which is used for data change. as figure 18-3 shows, when ucpol0 is zero the data will be changed at rising xck edge and sampled at falling xck edge. if ucpol0 is set, the data will be changed at falling xck edge and sampled at rising xck edge. 18.5 frame formats a serial frame is defined to be one character of data bits with synchronization bits (start and stop bits), and optionally a parity bit for error che cking. the usart accepts all 30 combinations of the following as valid frame formats: ? 1 start bit ? 5, 6, 7, 8, or 9 data bits ? no, even or odd parity bit ? 1 or 2 stop bits a frame starts with the start bit followed by the least significant data bit. then the next data bits, up to a total of nine, are succeeding, ending with the most significant bit. if enabled, the parity bit is inserted after the data bits, before the stop bits. when a complete frame is transmitted, it can f xck f osc 4 ----------- < rxd / txd xck rxd / txd xck ucpol = 0 ucpol = 1 sample sample
at90scr100/116/132 250 tpr0327b ? vic ? 16fev11 be directly followed by a new frame, or the communication line can be set to an idle (high) state. figure 18-4 illustrates the possible combinations of the frame formats. bits inside brackets are optional. figure 18-4. frame formats st start bit, always low. (n) data bits (0 to 8). p parity bit. can be odd or even. sp stop bit, always high. idle no transfers on the communication line (rxd0 or txd0). an idle line must be high. the frame format used by the usart is set by the ucsz02:0, upm01:0 and usbs0 bits in ucsr0b and ucsr0c. the receiver and transmitter use the same setting. note that changing the setting of any of these bits will corrupt all ongoing communication for both the receiver and transmitter. the usart character size (ucsz02:0) bits select the number of data bits in the frame. the usart parity mode (upm01:0) bits enable and set the type of parity bit. the selection between one or two stop bits is done by the usart stop bit select (usbs0) bit. the receiver ignores the second stop bit. an fe (frame error) will therefore only be detected in the cases where the first stop bit is zero. 18.5.1 parity bit calculation the parity bit is calculated by doing an exclusive-or of all the data bits. if odd parity is used, the result of the exclusive or is inverted. the relation between the parity bit and data bits is as follows:: p even parity bit using even parity p odd parity bit using odd parity d n data bit n of the character if used, the parity bit is located between the last data bit and first stop bit of a serial frame. 18.6 usart initialization the usart has to be initialized before any communication can take place. the initialization pro- cess normally consists of setting the baud rate, setting frame format and enabling the transmitter or the receiver depending on the usage. for interrupt driven by usart operation, 1 0 2 3 4 [5] [6] [7] [8] [p] st sp1 [sp2] (st / idle) (idle) frame p even d n 1 ? d 3 d 2 d 1 d 0 0 p odd d n 1 ? d 3 d 2 d 1 d 0 1 = =
251 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 the global interrupt flag should be cleared (and interrupts globally disabled) when doing the initialization. before doing a re-initialization with changed baud rate or frame format, be sure that there are no ongoing transmissions during the period the registers are changed. the txc0 flag can be used to check that the transmitter has completed all transfers, and the rxc flag can be used to check that there are no unread data in the receive buffer . the following simple usart initialization code examples show one assembly and one c func- tion that are equal in functionality. the examples assume asynchronous operation using polling (no interrupts enabled) and a fixed frame format. the baud rate is given as a function parameter. for the assembly code, the baud rate parameter is assumed to be stored in the r17:r16 registers. note: 1. see ?about code examples? on page 21. more advanced initialization routines can be made that include frame format as parameters, dis- able interrupts and so on. however, many applications use a fixed setting of the baud and control registers, and for these types of applications the initialization code can be placed directly in the main routine, or be combined with initialization code for other i/o modules. note note the txc0 flag must be cleared before eac h transmission (before udr0 is writ- ten) if it is used for this purpose. assembly code example (1) usart_init: ; set baud rate out ubrrh0, r17 out ubrrln0 r16 ; enable receiver and transmitter ldi r16, (1<>8); ubrrl0 = ( unsigned char )baud; /* enable receiver and transmitter */ ucsr0b = (1< at90scr100/116/132 252 tpr0327b ? vic ? 16fev11 18.7 data transmission ? the usart transmitter the usart transmitter is enabled by setting the transmit enable (txen) bit in the ucsr0b register. when the transmitter is enabled, the normal port operation of the txd0 pin is overrid- den by the usart and given the function as the transmitter?s serial output. the baud rate, mode of operation and frame format must be set up once before doing any transmissions. if syn- chronous operation is used, the clock on the xck pin will be overridden and used as transmission clock. 18.7.1 sending frames with 5 to 8 data bit a data transmission is initiated by loading the transmit buffer with the data to be transmitted. the cpu can load the transmit buffer by writing to the udr0 i/o location. the buffered data in the transmit buffer will be moved to the shift register when the shift register is ready to send a new frame. the shift register is loaded with new data if it is in idle state (no ongoing transmission) or immediately after the last stop bit of the previous frame is transmitted. when the shift register is loaded with new data, it will transfer one complete frame at the rate given by the baud register, u2x0 bit or by xck depending on mode of operation. the following code examples show a simple u sart transmit function based on polling of the data register empty (udre0) flag. when using frames with less than eight bits, the most sig- nificant bits written to the udr0 are ignored. the usart has to be initialized before the function can be used. for the assembly code, the data to be sent is assumed to be stored in register r16 note: 1. see ?about code examples? on page 21. the function simply waits for the transmit buffer to be empty by checking the udre0 flag, before loading it with new data to be transmitted. if the data register empty interrupt is utilized, the interrupt routine writes the data into the buffer. assembly code example (1) usart_transmit: ; wait for empty transmit buffer sbis ucsr0a,udre0 rjmp usart_transmit ; put data (r16) into buffer, sends the data out udr0,r16 ret c code example (1) void usart_transmit( unsigned char data ) { /* wait for empty transmit buffer */ while ( !( ucsr0a & (1< 253 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 18.7.2 sending frames with 9 data bit if 9-bit characters are used (ucsz0 = 7), the ninth bit must be written to the txb8 bit in ucsr0b before the low byte of the character is written to udr0. the following code examples show a transmit function that handles 9-bit char acters. for the assembly code, the data to be sent is assumed to be stored in registers r17:r16. note: 1. these transmit functions are written to be general functions. they can be optimized if the con- tents of the ucsr0b is static. for example, only the txb8 bit of the ucsr0b register is used after initialization. see ?about code examples? on page 21. the ninth bit can be used for indicating an address frame when using multi processor communi- cation mode or for other protocol handling as for example synchronization. 18.7.3 transmitter flags and interrupts the usart transmitter has two flags that indicate its state: usart data register empty (udre0) and transmit complete (txc0). both flags can be used to generate interrupts. the data register empty (udre0) flag indicates whether the transmit buffer is ready to receive new data. this bit is set when the transmit buffer is empty, and cleared when the transmit buffer contains data to be transmitted that has not already been moved into the shift register. for compatibility with future devices, always write this bit to zero when writing the ucsr0a register. assembly code example (1) usart_transmit: ; wait for empty transmit buffer sbis ucsr0a,udre0 rjmp usart_transmit ; copy 9th bit from r17 to txb8 cbi ucsr0b,txb8 sbrc r17,0 sbi ucsr0b,txb8 ; put lsb data (r16) into buffer, sends the data out udr0,r16 ret c code example (1) void usart_transmit( unsigned int data ) { /* wait for empty transmit buffer */ while ( !( ucsr0a & (1< at90scr100/116/132 254 tpr0327b ? vic ? 16fev11 when the data register empty interrupt enable (udrie0) bit in ucsr0b is written to one, the usart data register empty interrupt will be executed as long as udre0 is set (assuming that global interrupts are enabled). udre0 is cleared by writing udr0. when interrupt-driven data transmission is used, the data register empty interrupt routine must either write new data to udr0 in order to clear udre0 or disable the data register empty interrupt, otherwise a new interrupt will occur once the interrupt routine terminates. the transmit complete (txc0) flag bit is set when the entire frame in the transmit shift regis- ter has been shifted out and there are no new data currently present in the transmit buffer. the txc0 flag bit is automatically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. the txc0 flag is useful in half-duplex communica- tion interfaces (like the rs-485 standard), where a transmitting application must enter receive mode and free the communication bus immediately after completing the transmission. when the transmit compete interrupt enable (txcie0) bit in ucsr0b is set, the usart transmit complete interrupt will be executed when the txc0 flag becomes set (provided that global interrupts are enabled). when the transmit complete interrupt is used, the interrupt han- dling routine does not have to clear the txc0 flag, this is done automatically when the interrupt is executed. 18.7.4 parity generator the parity generator calculates the parity bit for the serial frame data. when parity bit is enabled (upm01 = 1), the transmitter control logic inserts the parity bit between the last data bit and the first stop bit of the frame that is sent. 18.7.5 disabling the transmitter the disabling of the transmitter (setting the txen to zero) will not become effective until ongo- ing and pending transmissions are completed, i.e., when the transmit shift register and transmit buffer register do not contain data to be transmitted. when disabled, the transmitter will no longer override the txd0 pin. 18.8 data reception ? the usart receiver the usart receiver is enabled by writing the receive enable (rxen0) bit in the ucsr0b register to one. when the receiver is enabled, the normal pin operation of the rxd0 pin is over- ridden by the usart and given the function as the receiver?s serial input. the baud rate, mode of operation and frame format must be set up once before any serial reception can be done. if synchronous operation is used, the clock on the xck pin will be used as transfer clock. 18.8.1 receiving frames with 5 to 8 data bits the receiver starts data reception when it detects a valid start bit. each bit that follows the start bit will be sampled at the baud rate or xck clock, and shifted into the receive shift register until the first stop bit of a frame is received. a second stop bit will be ignored by the receiver. when the first stop bit is received, i.e., a complete serial frame is present in the receive shift register, the contents of the shift register will be moved into the receive buffer. the receive buffer can then be read by reading the udr0 i/o location. the following code example shows a simple usart receive function based on polling of the receive complete (rxc0) flag. when using frames with less than eight bits the most significant
255 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 bits of the data read from the udr0 will be masked to zero. the usart has to be initialized before the function can be used. note: 1. see ?about code examples? on page 21. the function simply waits for data to be present in the receive buffer by checking the rxc0 flag, before reading the buffer and returning the value. 18.8.2 receiving frames with 9 data bits if 9-bit characters are used (ucsz0=7) the ninth bit must be read from the rxb80 bit in ucsr0b before reading the low bits from the udrn. this rule applies to the fe0, dor0 and upe0 status flags as well. read status from ucsr0a, then data from udr0. reading the udr0 i/o location will change the state of the receive buffer fifo and consequently the txb80, fe0, dor0 and upe0 bits, which all are stored in the fifo, will change. the following code example shows a simple usart receive function that handles both nine bit characters and the status bits. assembly code example (1) usart_receive: ; wait for data to be received sbis ucsr0a, rxc0 rjmp usart_receive ; get and return received data from buffer in r16, udr0 ret c code example (1) unsigned char usart_receive( void ) { /* wait for data to be received */ while ( !(ucsr0a & (1< at90scr100/116/132 256 tpr0327b ? vic ? 16fev11 note: 1. see ?about code examples? on page 21. the receive function example reads all the i/o registers into the register file before any com- putation is done. this gives an optimal receive buffer utilization since the buffer location read will be free to accept new data as early as possible. assembly code example (1) usart_receive: ; wait for data to be received sbis ucsr0a, rxc0 rjmp usart_receive ; get status and 9th bit, then data from buffer in r18, ucsr0a in r17, ucsr0b in r16, udr0 ; if error, return -1 andi r18,(1<> 1) & 0x01; return ((resh << 8) | resl); }
257 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 18.8.3 receive compete flag and interrupt the usart receiver has one flag that indicates the receiver state. the receive complete (rxc0) flag indicates if there are unread data present in the receive buf- fer. this flag is one when unread data exist in the receive buffer, and zero when the receive buffer is empty (i.e., does not contain any unread data). if the receiver is disabled (rxen0 = 0), the receive buffer will be flushed and consequently the rxc0 bit will become zero. when the receive complete interrupt enable (rxcie0) in ucsr0b is set, the usart receive complete interrupt will be executed as long as the rxc0 flag is set (provided that global inter- rupts are enabled). when interrupt-driven data reception is used, the receive complete routine must read the received data from udr0 in order to clear the rxc0 flag, otherwise a new inter- rupt will occur once the interrupt routine terminates. 18.8.4 receiver error flags the usart receiver has three error flags: frame error (fe0), data overrun (dor0) and parity error (upe0). all can be accessed by reading ucsr0a. common for the error flags is that they are located in the receive buffer together with the frame for which they indicate the error status. due to the buffering of the error flags, the ucsr0a must be read before the receive buffer (udr0), since reading the udr0 i/o location changes the buffer read location. another equality for the error flags is that they can not be altered by software doing a write to the flag location. however, all flags must be set to zero when the ucsr0a is written for upward compatibility of future usart implementations. none of the error flags can generate interrupts. the frame error (fe0) flag indicates the state of the first stop bit of the next readable frame stored in the receive buffer. the fe0 flag is zero when the stop bit was correctly read (as one), and the fe0 flag will be one when the stop bit was incorrect (zero). this flag can be used for detecting out-of-sync conditions, detecting break conditions and protocol handling. the fe0 flag is not affected by the setting of the usbs0 bit in ucsr0c since the receiver ignores all, except for the first, stop bits. for compatibility with future devices, always set this bit to zero when writing to ucsr0a. the data overrun (dor0) flag indicates data loss due to a receiver buffer full condition. a data overrun occurs when the receive buffer is full (two characters), it is a new character wait- ing in the receive shift register, and a new start bit is detected. if the dor0 flag is set there was one or more serial frame lost between the frame last read from udr0, and the next frame read from udr0. for compatibility with future devices, always write this bit to zero when writing to ucsr0a. the dor0 flag is cleared when the frame received was successfully moved from the shift register to the receive buffer. the parity error (upe0) flag indicates that the next frame in the receive buffer had a parity error when received. if parity check is not enabled the upe0 bit will always be read zero. for compatibility with future devices, always set this bit to zero when writing to ucsr0a. for more details see ?parity bit calculation? on page 250 and ?parity checker? on page 257 . 18.8.5 parity checker the parity checker is active when the high usart parity mode (upm01) bit is set. type of par- ity check to be performed (odd or even) is selected by the upm00 bit. when enabled, the parity checker calculates the parity of the data bits in incoming frames and compares the result with the parity bit from the serial frame. the result of the check is stored in the receive buffer together
at90scr100/116/132 258 tpr0327b ? vic ? 16fev11 with the received data and stop bits. the parity error (upe0) flag can then be read by software to check if the frame had a parity error. the upe0 bit is set if the next character that can be read from the receive buffer had a parity error when received and the parity checking was enabled at that point (upm01 = 1). this bit is valid until the receive buffer (udr0) is read. 18.8.6 disabling the receiver in contrast to the transmitter, disabling of the receiver will be immediate. data from ongoing receptions will therefore be lost. when disabled (i.e., the rxen0 is set to zero) the receiver will no longer override the normal function of the rxd0 port pin. the receiver buffer fifo will be flushed when the receiver is disabled. remaining data in the buffer will be lost 18.8.7 flushing the receive buffer the receiver buffer fifo will be flushed when the receiver is disabled, i.e., the buffer will be emptied of its contents. unread data will be lost. if the buffer has to be flushed during normal operation, due to for instance an error condition, read the udr0 i/o location until the rxc0 flag is cleared. the following code example shows how to flush the receive buffer. note: 1. see ?about code examples? on page 21. 18.9 asynchronous data reception the usart includes a clock recovery and a data recovery unit for handling asynchronous data reception. the clock recovery logic is used for synchronizing the internally generated baud rate clock to the incoming asynchronous serial frames at the rxd0 pin. the data recovery logic sam- ples and low pass filters each incoming bit, thereby improving the noise immunity of the receiver. the asynchronous reception operational range depends on the accuracy of the inter- nal baud rate clock, the rate of the incoming frames, and the frame size in number of bits. 18.9.1 asynchronous clock recovery the clock recovery logic synchronizes internal clock to the incoming serial frames. figure 18-5 illustrates the sampling process of the start bit of an incoming frame. the sample rate is 16 times the baud rate for normal mode, and eight times the baud rate for double speed mode. the hor- izontal arrows illustrate the synchronization va riation due to the sampling process. note the larger time variation is obtained when using the double speed mode (u2x0 = 1) of operation. assembly code example (1) usart_flush: sbis ucsr0a, rxc0 ret in r16, udr0 rjmp usart_flush c code example (1) void usart_flush( void ) { unsigned char dummy; while ( ucsr0a & (1< 259 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 samples denoted zero are samples done when the rxd0 line is idle (i.e., no communication activity). figure 18-5. start bit sampling when the clock recovery logic detects a high (idle) to low (start) transition on the rxd0 line, the start bit detection sequence is initiated. let sa mple 1 denote the first zero-sample as shown in the figure. the clock recovery logic then uses samples 8, 9, and 10 for normal mode, and sam- ples 4, 5, and 6 for double speed mode (indicated with sample numbers inside boxes on the figure), to decide if a valid start bit is received. if two or more of these three samples have logical high levels (the majority wins), the start bit is rejected as a noise spike and the receiver starts looking for the next high to low-transition. if however, a valid start bit is detected, the clock recov- ery logic is synchronized and the data recovery can begin. the synchronization process is repeated for each start bit. 18.9.2 asynchronous data recovery when the receiver clock is synchronized to the start bit, the data recovery can begin. the data recovery unit uses a state machine that has 16 states for each bit in normal mode and eight states for each bit in double speed mode. figure 18-6 shows the sampling of the data bits and the parity bit. each of the samples is given a number that is equal to the state of the recovery unit. figure 18-6. sampling of data and parity bit the decision of the logic level of the received bit is taken by doing a majority voting of the logic value to the three samples in the center of the received bit. the center samples are emphasized on the figure by having the sample number inside boxes. the majority voting process is done as follows: if two or all three samples have high levels, the received bit is registered to be a logic 1. if two or all three samples have low levels, the received bit is registered to be a logic 0. this majority voting process acts as a low pass filter for the incoming signal on the rxd0 pin. the recovery process is then repeated until a complete frame is received. including the first stop bit. note that the receiver only uses the first stop bit of a frame. figure 18-7 shows the sampling of the stop bit and the earliest possible beginning of the start bit of the next frame. 1234567 8 9 10 11 12 13 14 15 16 12 start idle 0 0 bit 0 3 123 4 5 678 12 0 rxd sample (u2x = 0) sample (u2x = 1) 1234567 8 9 10 11 12 13 14 15 16 1 bit n 123 4 5 678 1 rxd sample (u2x = 0) sample (u2x = 1)
at90scr100/116/132 260 tpr0327b ? vic ? 16fev11 figure 18-7. stop bit sampling and next start bit sampling the same majority voting is done to the stop bit as done for the other bits in the frame. if the stop bit is registered to have a logic 0 value, the frame error (fe0) flag will be set. a new high to low transition indicating the start bit of a new frame can come right after the last of the bits used for majority voting. for normal speed mode, the first low level sample can be at point marked (a) in figure 18-7 . for double speed mode the first low level must be delayed to (b). (c) marks a stop bit of full length. the early start bit detection influences the operational range of the receiver. 18.9.3 asynchronous operational range the operational range of the receiver is dependent on the mismatch between the received bit rate and the internally generated baud rate. if the transmitter is sending frames at too fast or too slow bit rates, or the internally generated baud rate of the receiver does not have a similar (see table 18-2 ) base frequency, the receiver will not be able to synchronize the frames to the start bit. the following equations can be used to calculate the ratio of the incoming data rate and internal receiver baud rate. d sum of character size and parity size (d = 5 to 10 bit) s samples per bit. s = 16 for normal speed mode and s = 8 for double speed mode. s f first sample number used for majority voting. s f = 8 for normal speed and s f = 4 for double speed mode. s m middle sample number used for majority voting. s m = 9 for normal speed and s m = 5 for double speed mode. r slow is the ratio of the slowest incoming data rate that can be accepted in relation to the receiver baud rate. r fast is the ratio of the fastest incoming data rate that can be accepted in relation to the receiver baud rate. table 18-2 and table 18-3 list the maximum receiver baud rate error that can be tolerated. note that normal speed mode has higher toleration of baud rate variations. 1234567 8 9 10 0/1 0/1 0/1 stop 1 123 4 5 6 0/1 rxd sample (u2x = 0) sample (u2x = 1) (a) (b) (c) table 18-1 . r slow d 1 + () s s 1 ? ds ? s f ++ ------------------------------------------ - = r fast d 2 + () s d 1 + () ss m + ----------------------------------- =
261 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 the recommendations of the maximum receiver baud rate error was made under the assump- tion that the receiver and transmitter equally divides the maximum total error. there are two possible sources for the receivers baud rate error. the receiver?s system clock (xtal) will always have some minor instability over the supply voltage range and the tempera- ture range. when using a crystal to generate the system clock, this is rarely a problem, but for a resonator the system clock may differ more than 2% depending of the resonators tolerance. the second source for the error is more controllable. the baud rate generator can not always do an exact division of the system frequency to get the baud rate wanted. in this case an ubrr value that gives an acceptable low error can be used if possible. 18.10 multi-processor communication mode setting the multi-processor communication mode (mpcm0) bit in ucsr0a enables a filtering function of incoming frames received by the usart receiver. frames that do not contain address information will be ignored and not put into the receive buffer. this effectively reduces the number of incoming frames that has to be handled by the cpu, in a system with multiple mcus that communicate via the same serial bus. the transmitter is unaffected by the mpcm0 setting, but has to be used differently when it is a part of a system utilizing the multi-processor communication mode. if the receiver is set up to receive frames that contain 5 to 8 data bits, then the first stop bit indi- cates if the frame contains data or address information. if the receiver is set up for frames with table 18-2. recommended maximum receiver baud rate error for normal speed mode (u2xn = 0) d # (data+parity bit) r slow (%) r fast (%) max total error (%) recommended max receiver error (%) 5 93.20 106.67 +6.67/-6.8 3.0 6 94.12 105.79 +5.79/-5.88 2.5 7 94.81 105.11 +5.11/-5.19 2.0 8 95.36 104.58 +4.58/-4.54 2.0 9 95.81 104.14 +4.14/-4.19 1.5 10 96.17 103.78 +3.78/-3.83 1.5 table 18-3. recommended maximum receiver baud rate error for double speed mode (u2xn = 1) d # (data+parity bit) r slow (%) r fast (%) max total error (%) recommended max receiver error (%) 5 94.12 105.66 +5.66/-5.88 2.5 6 94.92 104.92 +4.92/-5.08 2.0 7 95.52 104,35 +4.35/-4.48 1.5 8 96.00 103.90 +3.90/-4.00 1.5 9 96.39 103.53 +3.53/-3.61 1.5 10 96.70 103.23 +3.23/-3.30 1.0
at90scr100/116/132 262 tpr0327b ? vic ? 16fev11 nine data bits, then the ninth bit (rxb8n) is used for identifying address and data frames. when the frame type bit (the first stop or the ninth bit) is one, the frame contains an address. when the frame type bit is zero the frame is a data frame. the multi-processor communication mode enables several slave mcus to receive data from a master mcu. this is done by first decoding an address frame to find out which mcu has been addressed. if a particular slave mcu has been addressed, it will receive the following data frames as normal, while the other slave mcus will ignore the received frames until another address frame is received. 18.10.1 using mpcm0 for an mcu to act as a master mcu, it can use a 9-bit character frame format (ucsz0 = 7). the ninth bit (txb80) must be set when an address frame (txb80 = 1) or cleared when a data frame (txb = 0) is being transmitted. the slave mcus must in this case be set to use a 9-bit character frame format. the following procedure should be used to exchange data in multi-processor communication mode: 1. all slave mcus are in multi-processor communication mode (mpcm0 in ucsr0a is set). 2. the master mcu sends an address frame, and all slaves receive and read this frame. in the slave mcus, the rxc0 flag in ucsr0a will be set as normal. 3. each slave mcu reads the udr0 register and determines if it has been selected. if so, it clears the mpcm0 bit in ucsr0a, otherwise it waits for the next address byte and keeps the mpcm0 setting. 4. the addressed mcu will receive all data frames until a new address frame is received. the other slave mcus, which still have the mpcm0 bit set, will ignore the data frames. 5. when the last data frame is received by the addressed mcu, the addressed mcu sets the mpcm0 bit and waits for a new address frame from master. the process then repeats from 2. using any of the 5- to 8-bit character frame formats is possible, but impractical since the receiver must change between using n and n+1 character frame formats. this makes full- duplex operation difficult since the transmitter and receiver uses the same character size set- ting. if 5- to 8-bit character frames are used, the transmitter must be set to use two stop bit (usbs0 = 1) since the first stop bit is used for indicating the frame type. do not use read-modify-write instructions (sbi and cbi) to set or clear the mpcm0 bit. the mpcm0 bit shares the same i/o location as the txc0 flag and this might accidentally be cleared when using sbi or cbi instructions.
263 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 18.11 usart register description 18.11.1 udr0 ? usart i/o data register n the usart transmit data buffer register and usart receive data buffer registers share the same i/o address referred to as usart data register or udr0. the transmit data buffer reg- ister (txb) will be the destination for data written to the udr0 register location. reading the udr0 register location will return the contents of the receive data buffer register (rxb). for 5-, 6-, or 7-bit characters the upper unused bits will be ignored by the transmitter and set to zero by the receiver. the transmit buffer can only be written when the udre0 flag in the ucsr0a register is set. data written to udr0 when the udre0 flag is not set, will be ignored by the usart transmit- ter. when data is written to the transmit buffer, and the transmitter is enabled, the transmitter will load the data into the transmit shift register when the shift register is empty. then the data will be serially transmitted on the txd0 pin. the receive buffer consists of a two level fifo. the fifo will change its state whenever the receive buffer is accessed. due to this behavior of the receive buffer, do not use read-modify- write instructions (sbi and cbi) on this location. be careful when using bit test instructions (sbic and sbis), since these also will change the state of the fifo. 18.11.2 ucsr0a ? usart control and status register a ? bit 7 ? rxc0: usart receive complete this flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). if the receiver is disabled, the receive buffer will be flushed and consequently the rxc0 bit will become zero. the rxc0 flag can be used to generate a receive complete interrupt (see description of the rxcie0 bit). ? bit 6 ? txc0: usart transmit complete this flag bit is set when the entire frame in the transmit shift register has been shifted out and there are no new data currently present in the transmit buffer (udr0). the txc0 flag bit is auto- matically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. the txc0 flag can generate a transmit complete interrupt (see description of the txcie0 bit). ? bit 5 ? udre0: usart data register empty bit 7 6 5 4 3 2 1 0 udr0 $0000c6 rxb[7..0] (read) $0000c6 txb[7..0] (write) read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 $0000c0 rxc0 txc0 udre0 fe0 dor0 upe0 u2x0 mpcm0 ucsr0a read/write r r/w r r r r r/w r/w initial value 0 0 1 0 0 0 0 0 0x20
at90scr100/116/132 264 tpr0327b ? vic ? 16fev11 the udre0 flag indicates if the transmit buffer (udr0) is ready to receive new data. if udre0 is one, the buffer is empty, and therefore ready to be written. the udre0 flag can generate a data register empty interrupt (see description of the udrie0 bit). udre0 is set after a reset to indicate that the transmitter is ready. ? bit 4 ? fe0: frame error this bit is set if the next character in the re ceive buffer had a frame error when received. i.e., when the first stop bit of the next character in the receive buffer is zero. this bit is valid until the receive buffer (udr0) is read. the fe0 bit is zero when the stop bit of received data is one. always set this bit to zero when writing to ucsr0a. ? bit 3 ? dor0: data overrun this bit is set if a data overrun condition is detected. a data overrun occurs when the receive buffer is full (two characters), it is a new character waiting in the receive shift register, and a new start bit is detected. this bit is valid until the receive buffer (udr0) is read. always set this bit to zero when writing to ucsr0a. ? bit 2 ? upe0: usart parity error this bit is set if the next character in the receive buffer had a parity error when received and the parity checking was enabled at that point (upm01 = 1). this bit is valid until the receive buffer (udr0) is read. always set this bit to zero when writing to ucsr0a. ? bit 1 ? u2x0: double the usart transmission speed this bit only has effect for the asynchronous oper ation. write this bit to zero when using syn- chronous operation. writing this bit to one will reduce the divisor of the baud rate divider from 16 to 8 effectively dou- bling the transfer rate for asynchronous communication. ? bit 0 ? mpcm0: multi-processor communication mode this bit enables the multi-processor communica tion mode. when the mpcm0 bit is written to one, all the incoming frames received by the usart receiver that do not contain address infor- mation will be ignored. the transmitter is unaffected by the mpcm0 setting. for more detailed information see ?multi-processor communication mode? on page 261 . 18.11.3 ucsr0b ? usart control and status register b ? bit 7 ? rxcie0: rx complete interrupt enable 0 writing this bit to one enables interrupt on the rxc0 flag. a usart receive complete interrupt will be generated only if the rxcie0 bit is written to one, the global interrupt flag in sreg is written to one and the rxc0 bit in ucsr0a is set. ? bit 6 ? txcie0: tx complete interrupt enable 0 bit 76543 2 10 $0000c1 rxcie0 txcie0 udrie0 rxen0 txen0 ucsz02 rxb80 txb80 ucsr0b read/write r/w r/w r/w r/w r/w r/w r r/w initial value 0 0 0 0 0 0 0 0 0x00
265 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 writing this bit to one enables interrupt on the txc0 flag. a usart transmit complete interrupt will be generated only if the txcie0 bit is writt en to one, the global interrupt flag in sreg is written to one and the txc0 bit in ucsr0a is set. ? bit 5 ? udrie0: usart data regi ster empty inte rrupt enable 0 writing this bit to one enables interrupt on the udre0 flag. a data register empty interrupt will be generated only if the udrie0 bit is written to one, the global interrupt flag in sreg is written to one and the udre0 bit in ucsr0a is set. ? bit 4 ? rxen0: receiver enable 0 writing this bit to one enables the usart receiver. the receiver will override normal port oper- ation for the rxd0 pin when enabled. disabling the receiver will flush the receive buffer invalidating the fe0, dor0, and upe0 flags. ? bit 3 ? txen0: transmitter enable 0 writing this bit to one enables the usart transmitter. the transmitter will override normal port operation for the txd0 pin when enabled. the disabling of the transmitter (writing txenn0to zero) will not become effective until ongoing and pending transmissions are completed, i.e., when the transmit shift register and transmit buffer register do not contain data to be trans- mitted. when disabled, the transmitter will no longer override the txd0 port. ? bit 2 ? ucsz02: character size 0 the ucsz02 bits combined with the ucsz01:0 bit in ucsr0c sets the number of data bits (character size) in a frame the receiver and transmitter use. ? bit 1 ? rxb80: receive data bit 8 0 rxb80 is the ninth data bit of the received character when operating with serial frames with nine data bits. must be read before reading the low bits from udr0. ? bit 0 ? txb80: transmit data bit 8 0 txb80 is the ninth data bit in the character to be transmitted when operating with serial frames with nine data bits. must be written before writing the low bits to udr0. 18.11.4 ucsr0c ? usart control and status register c ? bits 7..6 ? umsel01..0 usart mode select these bits select the mode of operation of the usart0 as shown in table 18-4 .. bit 76543210 $0000c2 umsel01 umsel00 upm01 upm00 usbs0 ucsz01 ucsz00 ucpol0 ucsr0c 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 1 1 0 0x06 table 18-4. umsel0 bits settings umsel01 umsel00 mode 0 0 asynchronous usart 0 1 synchronous usart 1 0 (reserved) 1 1 master spi (mspim) (1)
at90scr100/116/132 266 tpr0327b ? vic ? 16fev11 note: 1. see ?usart in spi mode? on page 271 for full description of the master spi mode (mspim) operation ? bits 5..4 ? upm01..0: parity mode these bits enable and set type of parity gener ation and check. if enabled, the transmitter will automatically generate and send the parity of the tr ansmitted data bits within each frame. the receiver will generate a parity value for the incoming data and compare it to the upm0 setting. if a mismatch is detected, the upe0 flag in ucsr0a will be set. ? bit 3 ? usbs0: stop bit select this bit selects the number of stop bits to be inserted by the transmitter. the receiver ignores this setting. ? bit 2:1 ? ucsz01:0: character size the ucsz01:0 bits combined with the ucsz02 bit in ucsr0b sets the number of data bits (character size) in a frame the receiver and transmitter use. ? bit 0 ? ucpol0: clock polarity table 18-5. upm0 bits settings upm01 upm00 parity mode 00disabled 01reserved 1 0 enabled, even parity 1 1 enabled, odd parity table 18-6. usbs bit settings usbs0 stop bit(s) 01-bit 12-bit table 18-7. ucsz0 bits settings ucsz02 ucsz01 ucsz00 character size 0005-bit 0016-bit 0107-bit 0118-bit 100reserved 101reserved 110reserved 1119-bit
267 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 this bit is used for synchronous mode only. wr ite this bit to zero when asynchronous mode is used. the ucpol0 bit sets the relationship between data output change and data input sample, and the synchronous clock (xck). 18.11.5 ubrr0l and ubrr0h ? usart baud rate registers ? bit 15..12 ? reserved bits these bits are reserved for future use. for com patibility with future devices, these bit must be written to zero when ubrrh is written. ? bit 11..0 ? ubrr11..0: usart baud rate register this is a 12-bit register which contains the usart baud rate. the ubrrh contains the four most significant bits, and the ubrrl contains the eight least significant bits of the usart baud rate. ongoing transmissions by the transmitter and receiver will be corrupted if the baud rate is changed. writing ubrrl will trigger an immediate update of the baud rate prescaler. table 18-8. ucpoln bit settings ucpol0 transmitted data changed (output of txd0 pin) received data sampled (input on rxd0 pin) 0 rising xck edge falling xck edge 1 falling xck edge rising xck edge bit 76543 2 10 $0000c5 ---- ubrr[11..8] ubrrh0 $0000c4 ubrr[7..0] ubrrl0 read/writerrrrr/wr/wr/wr/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 0x00 00000 0 000x00
at90scr100/116/132 268 tpr0327b ? vic ? 16fev11 18.12 examples of baud rate setting for at90scr100/116/132 frequencies, the most commonly used baud rates for asynchronous operation can be generated by using the ubrr settings in table 18-9 and table 18-10 . ubrr values which yield an actual baud rate differing less than 0.5% from the target baud rate, are bold in the table. higher error ratings are acceptable, but the receiver will have less noise resis- tance when the error ratings are high, especially for large serial frames (see ?asynchronous operational range? on page 260 ). the error values are calculated using the following equation: note: 1. ubrr = 0, error = 0.0% error[%] baudrate closest match baudrate ------------------------------------------------------- - 1 ? ?? ?? 100% ? = table 18-9. examples of ubrr0 settings accessible oscillator frequencies baud rate (bps) f osc = 8.0000 mhz f osc = 16 mhz f osc = 19.2 mhz u2x0 = 0 u2x0 = 1 u2x0 = 0 u2x0 = 1 u2x0 = 0 u2x0 = 1 ubrr error ubrr error ubrr error ubrr error ubrr error ubrr error 2400 207 0.2% 416 -0.1% 416 -0.1% 832 0% 499 0% 999 0% 4800 103 0.2% 207 0.2% 207 0.2% 416 -0.1% 249 0% 499 0% 9600 51 0.2% 103 0.2% 103 0.2% 207 0.2% 124 0% 249 0% 14.4k 34 -0.8% 68 0.6% 68 0.6% 138 -0.1% 82 0.4% 166 -0.2% 19.2k 25 0.2% 51 0.2% 51 0.2% 103 0.2% 62 -0.8% 124 0% 28.8k 16 2.1% 34 -0.8% 34 -0.8% 68 0.6% 41 -0.8% 82 0.4% 38.4k 12 0.2% 25 0.2% 25 0.2% 51 0.2% 30 0.8% 62 -0.8% 57.6k 8 -3.5% 16 2.1% 16 2.1% 34 -0.8% 20 -0.8% 41 -0.8% 76.8k 6 -7% 12 0.2% 12 0.2% 25 0.2% 15 2.3% 30 0.8% 115.2k 3 8.5% 8 -3.5% 8 -3.5% 16 2.1% 9 4.2% 20 -0.8% 230.4k 1 8.5% 3 8.5% 3 8.5% 8 -3.5% 4 4.2% 9 4.2% 250k 1 0% 3 0% 3 0% 7 0% 4 -4% 9 -4% 500k 0 0% 1 0% 1 0% 3 0% 1 20% 4 -4% 1m - - 0 0% 0 0% 1 0% 0 20% 1 20% 1.5m------033.3%--%1-20% 2m ------00%--%020% max. (1) 500kbps 1mbps 1mbps 2mbps 1.2mbps 2.4mbps
269 tpr0327b ? vic ? 16fev11 18. usart at90scr100/116/132 note: 1. ubrr = 0, error = 0.0% table 18-10. examples of ubrr0 settings accessible oscillator frequencies (continued) baud rate (bps) f osc = 20 mhz u2x0 = 0 u2x0 = 1 ubrr error ubrr error 2400 520 0% 1041 0% 4800 259 0.2% 520 0% 9600 129 0.2% 259 0.2% 14.4k 86 -0.2% 173 -0.2% 19.2k 64 0.2% 129 0.2% 28.8k 42 0.9% 86 -0.2% 38.4k 32 -1.4% 64 0.2% 57.6k 21 -1.4% 42 0.9% 76.8k 15 1.7% 32 -1.4% 115.2k 10 -1.4% 21 -1.4% 230.4k 4 8.5% 10 -1.4% 250k 4 0% 9 0% 500k 2 -16.7% 4 0% 1m 0 25% 2 -16.7% 1.5m 1 -16.7% 2m 0 25% max. (1) 1.25mbps 2.5mbps
at90scr100/116/132 270 tpr0327b ? vic ? 16fev11
271 tpr0327b ? vic ? 16fev11 19. usart in spi mode at90scr100/116/132 19. usart in spi mode the universal synchronous and asynchronous serial receiver and transmitter (usart) can be set to a master spi compliant mode of operation. the master spi mode (mspim) has the follow- ing features: 19.1 features ? full duplex, three-wire synchronous data transfer ? master operation ? supports all four spi modes of operation (mode 0, 1, 2, and 3) ? lsb first or msb first data transfer (configurable data order) ? queued operation (double buffered) ? high resolution baud rate generator ? high speed operation (fxckmax = fck/2) ? flexible interrupt generation 19.2 overview setting both umsel01:0 bits to one enables the usart in mspim logic. in this mode of opera- tion the spi master control logic takes direct control over the usart resources. these resources include the transmitter and receiver shift register and buffers, and the baud rate gen- erator. the parity generator and checker, the data and clock recovery logic, and the rx and tx control logic is disabled. the usart rx and tx control logic is replaced by a common spi transfer control logic. however, the pin control logic and interrupt generation logic is identical in both modes of operation. the i/o register locations are the same in both modes. however, some of the functionality of the control registers changes when using mspim. 19.3 clock generation the clock generation logic generates the base clock for the transmitter and receiver. for usart mspim mode of operation only internal clock generation (i.e. master operation) is sup- ported. the data direction register for the xc k0 pin (ddr_xck0) must therefore be set to one (i.e. as output) for the usart in mspim to operate correctly. preferably the ddr_xck0 should be set up before the usart in mspim is enabled (i.e. txen0 and rxen0 bit set to one). the internal clock generation used in mspim mode is identical to the usart synchronous mas- ter mode. the baud rate or ubrr0 setting can therefore be calculated using the same equations, see table 19-1 : table 19-1. equations for calculating baud rate register setting operating mode equation for calculating baud rate (1) equation for calculating ubrr0 value synchronous master mode baud f osc 2 ubrr n 1 + () -------------------------------------- - = ubrr n f osc 2 baud -------------------- 1 ? =
at90scr100/116/132 272 tpr0327b ? vic ? 16fev11 baud baud rate (in bits per second, bps) f osc system oscillator clock frequency: clk io ubrr0 contents of the ubrr0h and ubrr0l registers, (0-4095) 19.4 spi data modes and timing there are four combinations of xck0 (sck) phase and polarity with respect to serial data, which are determined by control bits ucpha0 and ucpol0. the data transfer timing diagrams are shown in figure 19-1 . data bits are shifted out and latched in on opposite edges of the xck0 signal, ensuring sufficient time for data signals to stabilize. the ucpol0 and ucpha0 function- ality is summarized in table 19-2 . note that changing the setting of any of these bits will corrupt all ongoing communication for both the receiver and transmitter. figure 19-1. ucpha0 and ucpol0 data transfer timing diagrams. 19.5 frame formats a serial frame for the mspim is defined to be one character of 8 data bits. the usart in mspim mode has two valid frame formats: ? 8-bit data with msb first ? 8-bit data with lsb first a frame starts with the least or most significant data bit. then the next data bits, up to a total of eight, are succeeding, ending with the most or least significant bit accordingly. when a complete frame is transmitted, a new frame can directly follow it, or the communication line can be set to an idle (high) state. 1. the baud rate is defined to be the transfer rate in bit per second (bps) table 19-2. ucpol0 and ucpha0 functionality- ucpol0 ucpha0 spi mode leading edge trailing edge 0 0 0 sample (rising) setup (falling) 0 1 1 setup (rising) sample (falling) 1 0 2 sample (falling) setup (rising) 1 1 3 setup (falling) sample (rising) xck data setup (txd) data sample (rxd) xck data setup (txd) data sample (rxd) xck data setup (txd) data sample (rxd) xck data setup (txd) data sample (rxd) ucpol=0 ucpol=1 ucpha=0 ucpha=1
273 tpr0327b ? vic ? 16fev11 19. usart in spi mode at90scr100/116/132 the udord0 bit in ucsr0c sets the frame format used by the usart in mspim mode. the receiver and transmitter use the same setting. note that changing the setting of any of these bits will corrupt all ongoing communication for both the receiver and transmitter. 16-bit data transfer can be achieved by writin g two data bytes to udr0. a uart transmit com- plete interrupt will then signal that the 16-bit value has been shifted out. 19.5.1 usart mspim initialization the usart in mspim mode has to be initialized before any communication can take place. the initialization process normally consists of setting the baud rate, setting master mode of operation (by setting ddr_xck0 to one), setting frame format and enabling the transmitter and the receiver. only the transmitter can operate independently. for interrupt driven usart opera- tion, the global interrupt flag should be cleared (and thus interrupts globally disabled) when doing the initialization. before doing a re-initialization with changed baud rate, data mode, or frame format, be sure that there is no ongoing transmissions during the period the registers are changed. the txc0 flag can be used to check that the transmitter has completed all transfers, and the rxc0 flag can be used to check that there are no unread data in the receive buffer. note that the txc0 flag must be cleared before each transmission (before udr0 is written) if it is used for this purpose. the following simple usart initialization code examples show one assembly and one c func- tion that are equal in functionality. the exampl es assume polling (no interrupts enabled). the note note to ensure immediate initialization of the xck0 output the baud-rate register (ubrr0) must be zero at the time the transmitter is enabled. contrary to the nor- mal mode usart operation the ubrr0 must then be written to the desired value after the transmitter is enabled, but before the first transmission is started. setting ubrr0 to zero before enabling the transmitter is not necessary if the initialization is done immediately after a reset since ubrr0 is reset to zero.
at90scr100/116/132 274 tpr0327b ? vic ? 16fev11 baud rate is given as a function parameter. for the assembly code, the baud rate parameter is assumed to be stored in the r17:r16 registers. 19.6 data transfer using the usart in mspi mode requires the transmitter to be enabled, i.e. the txen0 bit in the ucsr0b register is set to one. when the transmitter is enabled, the normal port operation of the txd0 pin is overridden and given the function as the transmitter's serial output. enabling the receiver is optional and is done by setting the rxen0 bit in the ucsr0b register to one. when the receiver is enabled, the normal pin operation of the rxd0 pin is overridden and given the function as the receiver's serial input. the xck0 will in both cases be used as the transfer clock. after initialization the usart is ready for doing data transfers. a data transfer is initiated by writ- ing to the udr0 i/o location. this is the case for both sending and receiving data since the assembly code example usart_init: clr r18 out ubrr0h,r18 out ubrr0l,r18 ; setting the xck0 port pin as output, enables master mode. sbi xck0_ddr, xck0 ; set mspi mode of operation and spi data mode 0. ldi r18, (1< 275 tpr0327b ? vic ? 16fev11 19. usart in spi mode at90scr100/116/132 transmitter controls the transfer clock. the data written to udr0 is moved from the transmit buf- fer to the shift register when the shift register is ready to send a new frame. the following code examples show a simple usart in mspim mode transfer function based on polling of the data register empty (udre0) flag and the receive complete (rxc0) flag. the usart has to be initialized before the function can be used. for the assembly code, the data to be sent is assumed to be stored in register r16 and the data received will be available in the same register (r16) after the function returns. the function simply waits for the transmit buffer to be empty by checking the udre0 flag, before loading it with new data to be transmitted. the function then waits for data to be present in the receive buffer by checking the rxc0 flag, before reading the buffer and returning the value.. note note to keep the input buffer in sync with the number of data bytes transmitted, the udr0 register must be read once for each byte transmitted. the input buffer oper- ation is identical to normal usart mode, i. e. if an overflow occurs the character last received will be lost, not the first dat a in the buffer. this means that if four bytes are transferred, byte 1 first, then byte 2, 3, and 4, and the udr0 is not read before all transfers are completed, then byte 3 to be received will be lost, and not byte 1.
at90scr100/116/132 276 tpr0327b ? vic ? 16fev11 19.6.1 transmitter and receiver flags and interrupts the rxc0, txc0, and udre0 flags and corresp onding interrupts in usart in mspim mode are identical in function to the normal usart operation. however, the receiver error status flags (fe, dor, and pe) are not in use and is always read as zero. 19.6.2 disabling the transmitter or receiver the disabling of the transmitter or receiver in usart in mspim mode is identical in function to the normal usart operation. 19.7 usart mspim register description the following section describes the registers used for spi operation using the usart. 19.7.1 udr0 ? usart mspim i/o data register the function and bit description of the usart data register (udr0) in mspi mode is identical to normal usart operation. see ?udr0 ? usart i/o data register n? on page 263. assembly code example usart_mspim_transfer: ; wait for empty transmit buffer sbis ucsr0a, udre0 rjmp usart_mspim_transfer ; put data (r16) into buffer, sends the data out udr0,r16 ; wait for data to be received usart_mspim_wait_rxc0: sbis ucsr0a, rxc0 rjmp usart_mspim_wait_rxc0 ; get and return received data from buffer in r16, udr0 ret c code example unsigned char usart_receive( void ) { /* wait for empty transmit buffer */ while ( !( ucsr0a & (1< 277 tpr0327b ? vic ? 16fev11 19. usart in spi mode at90scr100/116/132 19.7.2 ucsr0a ? usart mspim cont rol and status register 0 a ? bit 7 ? rxc0: usart receive complete this flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). if the receiver is disabled, the receive buffer will be flushed and consequently the rxc0 bit will become zero. the rxc0 flag can be used to generate a receive complete interrupt (see description of the rxcie0 bit). ? bit 6 ? txc0: usart transmit complete this flag bit is set when the entire frame in the transmit shift register has been shifted out and there are no new data currently present in the transmit buffer (udr0). the txc0 flag bit is auto- matically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. the txc0 flag can generate a transmit complete interrupt (see description of the txcie0 bit). ? bit 5 ? udre0: usart data register empty the udre0 flag indicates if the transmit buffer (udr0) is ready to receive new data. if udre0 is one, the buffer is empty, and therefore ready to be written. the udre0 flag can generate a data register empty interrupt (see description of the udrie0 bit). udre0 is set after a reset to indicate that the transmitter is ready. ? bit 4..0 - reserved bits in mspi mode when in mspi mode, these bits are reserved for future use. for compatibility with future devices, these bits must be written to zero when ucsr0a is written. 19.7.3 ucsr0b ? usart mspim cont rol and status register 0 b ? bit 7 ? rxcie0: rx comp lete interrupt enable 0 writing this bit to one enables interrupt on the rxc0 flag. a usart receive complete interrupt will be generated only if the rxcie0 bit is written to one, the global interrupt flag in sreg is written to one and the rxc0 bit in ucsr0a is set. ? bit 6 ? txcie0: tx complete interrupt enable 0 writing this bit to one enables interrupt on the txc0 flag. a usart transmit complete interrupt will be generated only if the txcie0 bit is writt en to one, the global interrupt flag in sreg is written to one and the txc0 bit in ucsr0a is set. ? bit 5 ? udrie0: usart data regi ster empty inte rrupt enable 0 bit 76543 2 10 $0000c0 rxc0 txc0 udre0 - - - - - ucsr0a read/write r r/w r r r r r/w r/w initial value 0 0 1 0 0 0 0 0 0x20 bit 76543 2 10 $0000c1 rxcie0 txcie0 udrie0 rxe0 txe0 - - - ucsr0b read/write r/w r/w r/w r/w r/w r/w r r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 278 tpr0327b ? vic ? 16fev11 writing this bit to one enables interrupt on the udre0 flag. a data register empty interrupt will be generated only if the udrie0 bit is written to one, the global interrupt flag in sreg is written to one and the udre0 bit in ucsr0a is set. ? bit 4 ? rxen0: receiver enable 0 writing this bit to one enables the usart receiver. the receiver will override normal port oper- ation for the rxd0 pin when enabled. disabling the receiver will flush the receive buffer invalidating the fe0, dor0, and upe0 flags. ? bit 3 ? txen0: transmitter enable 0 writing this bit to one enables the usart transmitter. the transmitter will override normal port operation for the txd0 pin when enabled. the di sabling of the transmitter (writing txenn0to zero) will not become effective until ongoing a nd pending transmissions are completed, i.e., when the transmit shift register and transmit buffer register do not contain data to be trans- mitted. when disabled, the transmitter will no longer override the txd0 port ? bit 2..0 - reserved bits in mspi mode when in mspi mode, these bits are reserved for future use. for compatibility with future devices, these bits must be written to zero when ucsr0b is written. 19.7.4 ucsr0c ? usart mspim control and status register 0 c ? bit 7..6 - umsel01..0: usart mode select these bits select the mode of operation of the usart as shown in table 19-3 . see ?ucsr0c ? usart control and status register c? on page 265 for full description of the normal usart operation. the mspim is enabled when both umsel0 bits are set to one. the udord0, ucpha0, and ucpol0 can be set in the same write operation where the mspim is enabled. ? bit 5..3 - reserved bits in mspi mode when in mspi mode, these bits are reserved for future use. for compatibility with future devices, these bits must be written to zero when ucsr0c is written. ? bit 2 - udord0: data order when set to one the lsb of the data word is transmitted first. when set to zero the msb of the data word is transmitted first. refer to the frame formats section page 4 for details. ? bit 1 - ucpha0: clock phase bit 76543210 $0000c2 umsel01 umsel00 - - - udord0 ucpha ucpol0 ucsr0c 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 1 1 0 0x06 table 19-3. umsel0 bits settings umsel01 umsel00 mode 0 0 asynchronous usart 0 1 synchronous usart 1 0 (reserved) 1 1 master spi (mspim)
279 tpr0327b ? vic ? 16fev11 19. usart in spi mode at90scr100/116/132 the ucpha0 bit setting determine if data is sampled on the leasing edge (first) or tailing (last) edge of xck0. refer to the spi data modes and timing section page 4 for details. ? bit 0 - ucpol0: clock polarity the ucpol0 bit sets the polarity of the xck0 clock. the combination of the ucpol0 and ucpha0 bit settings determine the timing of the data transfer. refer to the spi data modes and timing section page 4 for details. 19.7.5 ubrr0l and ubrr0h ?usart mspim baud rate registers the function and bit description of the baud rate registers in mspi mode is identical to normal usart operation. see ?ubrr0l and ubrr0h ? usart baud rate registers? on page 267. 19.8 8/16-bit risc cpu usart mspim vs. 8/16-bit risc cpu spi the usart in mspim mode is fully compatible with the 8/16-bit risc cpu spi regarding: ? master mode timing diagram. ? the ucpol0 bit functionality is identical to the spi cpol bit. ? the ucpha0 bit functionality is identical to the spi cpha bit. ? the udord0 bit functionality is identical to the spi dord bit. however, since the usart in mspim mode reus es the usart resources, the use of the usart in mspim mode is somewhat different compared to the spi. in addition to differences of the control register bits, and that only master operation is supported by the usart in mspim mode, the following features differ between the two modules: ? the usart in mspim mode includes (double) buffering of the transmitter. the spi has no buffer. ? the usart in mspim mode receiver includes an additional buffer level. ? the spi wcol (write collision) bit is not included in usart in mspim mode. ? the spi double speed mode (spi2x) bit is not included. however, the same effect is achieved by setting ubrr0 accordingly. ? interrupt timing is not compatible. ? pin control differs due to the master only operation of the usart in mspim mode. a comparison of the usart in mspim mode and the spi pins is shown in table 19-4 on page 279 . table 19-4. comparison of usart in mspim mode and spi pins. usart_mspim spi comment txd0 mosi master out only rxd0 miso master in only xck0 sck (functionally identical) (n/a) ss not supported by usart in mspim
at90scr100/116/132 280 tpr0327b ? vic ? 16fev11
281 tpr0327b ? vic ? 16fev11 20. spi - serial peripheral interface at90scr100/116/132 20. spi - serial peripheral interface the serial peripheral interface (spi) allows synchronous data transfer between the at90scr100/116/132 and peripheral devices such as rf front-end chip. the at90scr100/116/132 spi includes the following features: 20.1 features ? full-duplex, three-wire synchronous data transfer ? master or slave operation ? lsb first or msb first data transfer ? seven programmable bit rates ? end of transmission interrupt flag ? write collision flag protection ? wake-up from idle mode ? double speed (ck/2) master spi mode 20.2 description usart can also be used in master spi mode. see ?usart in spi mode? on page 271. the power reduction spi bit, prspi, in ?prr0 ? power reduction register 0? on page 54 on page 50 must be written to zero to enable spi module. please refer to section 2. ?pin list configuration? on page 15 for spi pin placement. figure 20-1. spi block diagram spi2x spi2x divider /2/4/8/16/32/64/128 clk io
at90scr100/116/132 282 tpr0327b ? vic ? 16fev11 the interconnection between master and slave cpus with spi is shown in figure 20-2 . the sys- tem consists of two shift registers, and a master clock generator. the spi master initiates the communication cycle when pulling low the slave select ss pin of the desired slave. master and slave prepare the data to be sent in their respective shift registers, and the master generates the required clock pulses on the sck line to interchange data. data is always shifted from mas- ter to slave on the master out ? slave in, mosi, line, and from slave to master on the master in ? slave out, miso, line. after each data packet, the master will synchronize the slave by pulling high the slave select, ss , line. when configured as a master, the spi interface has no automatic control of the ss line. this must be handled by user software before communication can start. when this is done, writing a byte to the spi data register starts the spi clock generator, and the hardware shifts the eight bits into the slave. after shifting one byte , the spi clock generator stops, setting the end of transmission flag (spif). if the spi interrupt enable bit (spie) in the spcr register is set, an interrupt is requested. the master may continue to shift the next byte by writing it into spdr, or signal the end of packet by pulling high the slave select, ss line. the last incoming byte will be kept in the buffer register for later use. when configured as a slave, the spi interface will remain sleeping with miso tri-stated as long as the ss pin is driven high. in this state, software may update the contents of the spi data register, spdr, but the data will not be shifted out by incoming clock pulses on the sck pin until the ss pin is driven low. as one byte has been completely shifted, the end of transmission flag, spif is set. if the spi interrupt enable bit, spie, in the spcr register is set, an interrupt is requested. the slave may continue to plac e new data to be sent into spdr before reading the incoming data. the last incoming byte will be kept in the buffer register for later use. figure 20-2. spi master-slave interconnection the system is single buffered in the transmit direction 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 character must be read from the spi data register before the next character has been completely shifted in. oth- erwise, the first byte is lost. in spi slave mode, the control logic will sample the incoming signal of the sck pin. to ensure correct sampling of the clock signal, the minimum low and high periods should be: low period: longer than 2 cpu clock cycles. high period: longer than 2 cpu clock cycles. shift enable
283 tpr0327b ? vic ? 16fev11 20. spi - serial peripheral interface at90scr100/116/132 when the spi is enabled, the data direction of the mosi, miso, sck, and ss pins is overridden according to table 20-1 . table 20-1. spi pin overrides pin direction, master spi direction, slave spi mosi user defined input miso input user defined sck user defined input ss user defined input
at90scr100/116/132 284 tpr0327b ? vic ? 16fev11 the following code examples show how to initialize the spi as a master and how to perform a simple transmission. ddr_spi in the examples must be replaced by the actual data direction register controlling the spi pins. dd_mosi, dd_miso and dd_sck must be replaced by the actual data direction bits for these pins. e.g. if mosi is placed on pin pb5, replace dd_mosi with ddb5 and ddr_spi with ddrb. assembly code example spi_masterinit: ; set mosi and sck output, all others input ldi r17,(1< 285 tpr0327b ? vic ? 16fev11 20. spi - serial peripheral interface at90scr100/116/132 the following code examples show how to initialize the spi as a slave and how to perform a simple reception. assembly code example spi_slaveinit: ; set miso output, all others input ldi r17,(1< at90scr100/116/132 286 tpr0327b ? vic ? 16fev11 20.3 ss pin functionality 20.3.1 slave mode when the spi is configured as a slave, the slave select (ss) pin is always input. when ss is held low, the spi is activated, and 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 once the ss pin is driven high. the ss pin is useful for packet/byte synchronization to keep the slave bit counter synchronous with the master clock generator. when the ss pin is driven high, the spi slave will immediately reset the send and receive logic, and drop any partially received data in the shift register. 20.3.2 master mode 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. typically, the pin will be driving the ss pin of the spi slave. 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 configured as a master with the ss pin defined as an input, the spi system interprets this as another master selecting the spi as a slave and starting to send data to it. to avoid bus contention, the spi system takes the following actions: 1. the mstr bit in spcr is cleared and the spi system becomes a slave. as a result of the spi becoming a slave, the mosi and sck pins become inputs. 2. the spif flag in spsr is set, and if the spi interrupt is enabled, and the i-bit in sreg is set, the interrupt routine will be executed. thus, when interrupt-driven spi transmission 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. if the mstr bit has been cleared by a slave select, it must be set by the user to re-enable spi master mode. 20.4 spi registers 20.4.1 spcr ? spi control register ? bit 7 ? spie: spi interrupt enable this bit causes the spi interrupt to be executed if spif bit in the spsr register is set and the if the global interrupt enable bit in sreg is set. ? bit 6 ? spe: spi enable bit 76543210 0x2c (0x4c) spie spe dord mstr cpol cpha spr1 spr0 spcr read/write r/wr/wr/wr/wr/wr/wr/wr/w initial value000000000x00
287 tpr0327b ? vic ? 16fev11 20. spi - serial peripheral interface at90scr100/116/132 when the spe bit is written to one, the spi is enabled. this bit must be set to enable any spi operations. ? bit 5 ? dord: data order when the dord bit is written to one, the lsb of the data word is transmitted first. when the dord bit is written to zero, the msb of the data word is transmitted first. ? bit 4 ? mstr: master/slave select this bit selects master spi mode when written to one, and slave spi mode when written logic zero. if 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 mas- ter mode. ? bit 3 ? cpol: clock polarity when this bit is written to one, sck is high when idle. when cpol is written to zero, sck is low when idle. refer to figure 20-3 and figure 20-4 for an example. the cpol functionality is sum- marized below: ? bit 2 ? cpha: clock phase the settings of the clock phase bit (cpha) determine if data is sampled on the leading (first) or trailing (last) edge of sck. refer to figure 20-3 and figure 20-4 for an example. the cpol functionality is summarized below: ? 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 clk io is shown in the following table: table 20-2. cpol functionality cpol leading edge trailing edge 0 rising falling 1 falling rising table 20-3. cpha functionality cpha leading edge trailing edge 0 sample setup 1 setup sample table 20-4. relationship between sck and the oscillator frequency spi2x spr1 spr0 sck frequency 000 clk io / 4 001 clk io / 16 010 clk io / 64 011 clk io / 128 100 clk io / 2
at90scr100/116/132 288 tpr0327b ? vic ? 16fev11 20.4.2 spsr ? spi status register ? bit 7 ? spif: spi interrupt flag when a serial transfer is complete, the spif flag is set. an interrupt is generated if spie in spcr is set and global interrupts are enabled. 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 hardware when executing the corresponding interrupt handling vector. alternatively, the spif bit is cleared by first reading the spi status register with spif set, then accessing the spi data register (spdr). ? bit 6 ? wcol: write collision flag the wcol bit is set if the spi data register (spdr) is written during a data transfer. the wcol bit (and the spif bit) are cleared by first reading the spi status register with wcol set, and then accessing the spi data register. ? bit 5:1 ? res: reserved bits these bits are reserved bits in the at90scr100/116/132 and will always read as zero. ? bit 0 ? spi2x: double spi speed bit when this bit is written logic one the spi speed (sck frequency) will be doubled when the spi is in master mode (see table 20-4 ). this means that the minimum sck period will be two cpu clock periods. when the spi is configured as slave, the spi is only guaranteed to work at clk io /4 or lower. the spi interface on the at90scr100/116/132 is also used for program memory and eeprom downloading or uploading. see page 395 for serial programming and verification. 20.4.3 spdr ? spi data register 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. 101 clk io / 8 110 clk io / 32 111 clk io / 64 table 20-4. relationship between sck and the oscillator frequency spi2x spr1 spr0 sck frequency bit 76543210 0x2d (0x4d) spifwcol-----spi2x spsr read/writerrrrrrrr/w initial value000000000x00 bit 76543210 0x2e (0x4e) spdr [7:0] spdr read/write r/wr/wr/wr/wr/wr/wr/wr/w initial valuexxxxxxxx
289 tpr0327b ? vic ? 16fev11 20. spi - serial peripheral interface at90scr100/116/132 20.5 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 figure 20-3 and figure 20-4 . data bits are shifted out and latched in on opposite edges of the sck sig- nal, ensuring sufficient time for data signals to stabilize. this is clearly seen by summarizing table 20-2 and table 20-3 , as done below: figure 20-3. spi transfer format with cpha = 0 figure 20-4. spi transfer format with cpha = 1 table 20-5. cpol functionality leading edge trailing edge spi mode cpol=0, cpha=0 sample (rising) setup (falling) 0 cpol=0, cpha=1 setup (rising) sample (falling) 1 cpol=1, cpha=0 sample (falling) setup (rising) 2 cpol=1, cpha=1 setup (falling) sample (rising) 3 bit 1 bit 6 lsb msb sck (cpol = 0) mode 0 sample i mosi/miso change 0 mosi pin change 0 miso pin sck (cpol = 1) mode 2 ss msb lsb bit 6 bit 1 bit 5 bit 2 bit 4 bit 3 bit 3 bit 4 bit 2 bit 5 msb first (dord = 0) lsb first (dord = 1) sck (cpol = 0) mode 1 sample i mosi/miso change 0 mosi pin change 0 miso pin sck (cpol = 1) mode 3 ss msb lsb bit 6 bit 1 bit 5 bit 2 bit 4 bit 3 bit 3 bit 4 bit 2 bit 5 bit 1 bit 6 lsb msb msb first (dord = 0) lsb first (dord = 1)
at90scr100/116/132 290 tpr0327b ? vic ? 16fev11
291 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 21. high-speed spi controller this high speed spi (hsspi) interface comes with 4 dedicated pads (hsmiso, hsmosi, hssck, hsss ). 21.1 features ? support clock up to 20mhz in master and slave mode ? full-duplex, 4-wire synchronous data transfer ? master or slave operation ? transmission / reception ? three sources of interrupt: byte transm itted, time-out and reception overflow ? specific dma for fast copy from internal dpram to ram ? 4 dpram buffers of 16 bytes each: 2 for reception and 2 for transmission ? internal double buffering for high performance ? programmable clock and inter-bytes (guardtime) delays figure 21-1. hsspi block diagram 21.2 description the interconnection between master and slave cpus with hsspi is shown in figure 21-2 . the hsspi controller is enabled by setting the hsspicfg.hsspien bit (by default, the hsspi controller is in slave mode) and fully operational when the hsspisr.spickrdy bit is set. to select the frequency of the hsspi clock, the hsspicfg.spickdiv bits (described in page 301 ) hsspi clock (master) msb lsb hsspi status register hsspi control register hsspi interrupt request hsspi controller dpram buffer clock spien mstr cpol cpha internal data bus 32 32 32 hsmiso s m btd hsmosi hssck m s s m msb lsb rx 8-bit shift register tx 8-bit shift register spickrdy s m hsss clk hsspi
at90scr100/116/132 292 tpr0327b ? vic ? 16fev11 must be configured before enabling the hsspi controller. any attempt at modifying the hsspi clock frequency once the hsspi controller is enabled will not affect it. the hsspicfg.hsm- str bit selects either master or slave operations. the hsspi master initiates the communication cycle after pulling low the hsss line of the desired slave. the master and slave prepare the data to be sent using their respective shift registers or using the internal dpram (according to the hsspicfg.dpram bit), and the master generates the required clock pulses on the hssck line to exchange data. data is always shifted from master to slave on the master out - slave in, hsmosi line, and from slave to master on the master in - slave out, hsmiso line, simultaneously. figure 21-2. hsspi master - slave interconnection the dpram stores two 16 bytes buffers for transmission and two 16 bytes buffers for reception. 21.2.1 hsspi controller configured as a master when configured as a master, the hsspi interface has no automatic control of the hsss line. this must be handled by software before starting the communication. 21.2.1.1 one byte sending using shift register (without dpram) when the dpram is not activated (hsspicfg.dpram bit cleared) and a byte is written to the hsspi transmit data register (hsspitdr registe r), the hardware shifts the 8 bits (msb first) into the slave and receives a byte from the slave simultaneously. after shifting one byte, the byte transfer done flag (hsspiir.btd) is set. if global interrupt and the hsspiier.btdie bit have been previously set, an interrupt is generated. at this stage, the master can read the hsspirdr register to retrieve the byte sent by the other device. the hsspiir.btd flag must then be cleared by software. the figure below illustrates the way the hssp i works when configured as a master without dpram mode. master hsspi clock generator 8 bit shift register msb lsb master slave 8 bit shift register msb lsb hssck hsmosi hsmiso chip as master chip as slave
293 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 figure 21-3. hsspi - master without dpram operation 21.2.1.2 buffer sending with dpram and hsspidma (dpram mode) when the dpram is activated (hsspicfg.dpram bit set), the data to be sent must be written to one of the internal dpram buffers using the hsspidma. to do so, use the hsspidma mechanism to copy hsspidmab bytes from ram to dpram. it is not possible to copy more than 16 bytes per copy. the dpram targeted by t he copy is totally transparent to the user. once this is done, the number of bytes to be transmitted is written to the hsspicnt register. the hsspi interface will start to shift this number of bytes from the master to the slave and from the slave to the master simultaneously. if the hsspisr.txbufe = 1, new data can be copied in the second buffer using hsspidma again. after shifting all the bytes of one buffer, the byte transfer done flag (hsspiir.btd) is set. if the hsspi interrupt enable bit and the hsspi- ier.btdie bit have been previously set, an interrupt is generated. clear btd (hsspiir) (mandatory if irq mode) data to receive? configure spi guard time (hsspigtr) configure spick frequency (hsspifg) read data from hsspirdr yes no wait hsspickrdy write data to send into hsspitdr configure cpol, cpha, mstr=1, spien, dpram=0, btdie (if irq mode) wait btd (hsspiir)
at90scr100/116/132 294 tpr0327b ? vic ? 16fev11 at this point, the master can copy the received data from reception dpram into ram, using hsspidma. the hsspiir.btd flag must then be cleared by software. if the hsspiir.btd is set and the next buffer becomes full, the hsspiir.rcvof is set. if the hsspi interrupt enable bit and the hsspiier.rcvofie bit have been previously set, an inter- rupt is generated. the figure below illustrates the way the hsspi works when configured as a master with dpram/hsspidma. figure 21-4. spi - master with dpram/hsspidma activated configure spick frequency (hsspicfg) data to receive? configure spi guard time (hsspigtr) configure cpol, cpha, mstr=1, spien, dpram=1, btdie (if irq mode) wait spickrdy (hsspisr) read spicnt start copy of received data into ram using hsspidma. read received data directly in ram wait btd (hsspiir) clear btd (hsspiir) yes no nb_data to send or receive>16? txbufe? (hsspisr) init ram data and hsspidma copy data into dpram write 16 in hsspicnt prepare ram and hsspidma copy 16 or nb_data left data into dpram. write 16 or nb_data left in hsspicnt yes yes no no init ram data and hsspidma copy data into dpram write 16 in hsspicnt prepare ram and hsspidma copy nb_data left data into dpram. write nb_data left in hsspicnt
295 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 21.2.2 spi controller configured as a slave 21.2.2.1 one byte sending using shift register (without dpram) if the dpram is not activated (hsspicfg.dpram bit cleared), the software may update the contents of the hsspi transmit data register, spitdr, that will be shifted out by incoming clock pulses on the clock pin. as soon as the byte has been completely shifted, the byte transfer done flag (hsspiir.btd) is set. if global interrupt and the hsspiier.btdie bit have been previ- ously set, an interrupt is generated. at this stage, the slave can read the hsspirdr regi ster to retrieve the byte sent by the other device. the hsspicfg.btd flag must then be cleared by software. figure 21-5. hsspi - slave without dpram activated clear btd (hsspiir) (mandatory if irq mode) data to send? yes no wait spickrdy (hsspisr) write data to send into hsspitdr configure cpol, cpha, mstr=0, spien, dpram=0, btdie (if irq mode) wait btd (hsspiir) data to receive? wait btd (hsspiir) read data from hsspirdr no yes
at90scr100/116/132 296 tpr0327b ? vic ? 16fev11 21.2.2.2 buffer sending with dpram and hsspidma (dpram mode) when the dpram is activated (hsspicfg.dpram bit set), the data to be sent must be written to one of the internal dpram buffers using hsspidma. once this is done, the number of bytes to be transmitted is written to the hsspicnt re gister. when the master applies the clock, this number of bytes is shifted from the master to the slave and from the slave to the master simulta- neously. at this point, new data can be stored in the second buffer if the hsspisr.txbufe = 1. each time all the data in one of the buffers is sent, the byte transfer done flag (hsspiir.btd) is set. if global interrupt and the hsspiier.btdie bit have been previously set, an interrupt is generated. at this stage, the incoming data can be copied from internal dpram to ram using hsspidma. the hsspiir.btd flag must then be cleared by software. if the hsspiir.btd is set and the next buffer becomes full, the hsspiir.rcvof is set. if global interrupt and the hsspiier.rcvofie bit have been previously set, an interrupt is generated. the figures below ( figure 21-6 , figure 21-7 & figure 21-8 ) illustrate the way the spi works when configured as a slave with dpram mode.
297 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 figure 21-6. spi - slave with dpram operation - first part configure spick frequency (hsspicfg) use the timeout? configure hsspitimeout configure cpol, cpha, mstr=0, spien, dpram=1, btdie wait spickrdy (hsspisr) goto label "receive data" nb_data to send or receive>16? txbufe? (hsspisr) data to receive? wait btd (hsspiir) clear btd (hsspiir) yes yes yes no no no data to send? yes no yes no init ram data and hsspidma copy data into dpram write 16 in hsspicnt prepare ram and hsspidma copy 16 or nb_data left data into dpram. write 16 or nb_data left in hsspicnt init ram data and hsspidma copy data into dpram write 16 in hsspicnt prepare ram and hsspidma copy nb_data left data into dpram. write nb_data left in hsspicnt read spicnt start copy of received data into ram using hsspidma. read received data directly in ram
at90scr100/116/132 298 tpr0327b ? vic ? 16fev11 figure 21-7. spi - slave with dpram operation - second part if the number of bytes to be received or sent is not known, a timeout can be used. it can be acti- vated by entering a time bit value in the hsspitimeout and setting the hsspicr.sttto bit. as the amount of data is unknown, the two registers (hsspicnt) have to be set to the maxi- mum value, 16. when the timeout occurs, the hsspiir.timeout bit is set. if the hsspi interrupt enable bit and the hsspiier.timeoutie bit have been previously set, an interrupt is generated. the number of byte received is available in the hsspicnt register. clearing the hsspiir.timeout bit by soft or by setting the hsspicr.sttto bit will update the internal dpram nb_data to receive known? label "receive data" nb_data to receive >16? rx_buf_full? write nb_data to receive in hsspicnt write 16 in hsspicnt wait btd (hsspiir) write 16 in hsspicnt clear btd (hsspiir) yes yes no no yes no goto label "receive data uk" clear btd (hsspiir) nb_data to receive >16? yes write nb_data left in hsspicnt no read hsspicnt start copy of received data into ram using hsspidma. read received data directly in ram read hsspicnt start copy of received data into ram using hsspidma. read received data directly in ram
299 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 figure 21-8. spi - slave with dpram operation - third part in spi slave mode, the control logic will sample the incoming signal of the hssck pin. to ensure correct sampling of the clock signal, the frequency of the hsspi clock should never exceed f sckmax (f sckmax =24 mbits/s). when the hsspi is enabled, the data direction of the hsmosi, hsmiso, hssck, and hsss pins is overridden according to table 21-1 . table 21-1. spi pin overrides pin direction, master spi direction, slave spi mosi output input miso input output sck output input nss output input btd? write 16 in hsspicnt read nb_data in hsspicnt copy nb_data into ram using hsspidma. read received data directly into ram set bit hsspicr.stto yes no then timeout label "receive data uk" clear btd (hsspiir) set bit hsspicr.stto wait btd or timeout write 16 in hsspicnt end of reception. next loop copy 16 into ram using hsspidma. read received data directly into ram clear timeout (hsspiir) disable dma (clear hsspicfg.dpram) enable dma (set hsspicfg.dpram) wait dma ready (hsspisr.dpramrdy)
at90scr100/116/132 300 tpr0327b ? vic ? 16fev11 21.3 hsss line functionality 21.3.1 slave mode when the hsspi is configured as a slave (hsspicfg.hsmstr bit cleared), the slave select (hsss ) line is driven by the master device. the hsss has no effect on the hsspi logic. it is the software?s responsibility to manage the hsss level. 21.3.2 master mode when the hsspi is configured as a master (hsspicfg.hsmstr bit set), the hsss line is used to select the slave. 21.4 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 figure 21-9 and figure 21-10 . figure 21-9. spi transfer format with cpha = 0 figure 21-10. spi transfer format with cpha = 1
301 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 21.5 hsspi interface registers 21.5.1 hsspicfg - hsspi config register ? bits 7..5 - spickdiv2..0: spi clock divider ratio bits defines the hsspi clock divider ratio. the following table gives, for each combination of spickdiv2, spickdiv1 and spickdiv0, the division applied to the clock. figure 7-1 on page 41 gives information about the clock tree and base frequency for hsspi. note: 1. base frequency is clk io = 96mhz ? bit 4 - dpram: dpram bit when set (one), this bit enables the dpram/hsspidma systems. when cleared (zero), this bit disables the dpram/hsspidma systems. ? bit 3 - hscpha: high speed clock phase bit the settings of the clock phase bit (cpha) determine if data is sampled on the leading (first) or trailing (last) edge of hssck. refer to figure 21-9 and figure 21-10 . bit 7 6 5 4 3 2 1 0 $0000d9 spickdiv [2..0] dpram hscpha hscpol hsmstr hsspien hsspicfg read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 1 0 0 0 0 0 0 0 0x80 table 21-2. hsspi dividers (1) spickdiv2 sckckdiv1 sckckdiv0 divider external clock divider ratio (1) 00 04 24 mhz 0 0 1 5 19.2 mhz 01 06 16 mhz 01 18 12 mhz 10 012 8 mhz 10 124 4 mhz 11 048 2 mhz 11 196 1 mhz note note any attempt at modifying the hsspicfg.spickdiv value once the hsspi con- troller is enabled will not affect the hsspi clock frequency. note note after a dpram is disabled, the dpram is reset. this reset is active for two clock cycles of the dpram clock. it is recommended to do nothing on the dpram dur- ing these two clock cycles.
at90scr100/116/132 302 tpr0327b ? vic ? 16fev11 the cpha functionality is summarized below: ? bit 2 - hscpol: high speed clock polarity bit when this bit is written to one, sck is high when idle. when cpol is written to zero, sck is low when idle. refer to figure 21-9 and figure 21-10 . the cpol functionality is summarized below: ? bit 1 - hsmstr: high speed master/slave select bit this bit selects the master hsspi mode when set (one), and slave hsspi mode when cleared (zero). this bit is cleared by software or by hardware when the hsspicfg.hsspien gets cleared (dis- abling the hsspi). ? bit 0 - hsspien: high speed spi enable bit when this bit is set (one), the hsspi controller is enabled with the predefined configuration. when this bit is cleared (zero), the hsspi controller is disabled and hsspicfg.hsmstr is driven low. 21.5.2 hsspiir - hsspi interrupt register ? bit 7 - timeout: timeout interrupt bit this bit is set (one) when a timeout occurs. an interrupt is generated if hsspiier.timeoutie is set and global interrupt is enabled. this bit is cleared by software or by hardware when the hsspicfg.hsspien is toggled (enabling or disabling the hsspi). ? bit 6 - btd: byte transfer done bit table 21-3. cpha configuration cpha leading edge trailing edge 0 sample setup 1 setup sample table 21-4. cpol configuration cpol leading edge trailing edge 0 rising falling 1 falling rising note note configuring and activating the hsspi peripheral with the same instruction is a valid action. bit 76543 2 1 0 $0000da timeout btd rcvof nssre nssfe - - - hsspiir read/write r/w r/w r/w r/w r/w r r r initial value00000 0 0 0 0x00
303 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 this bit is set (one) when a serial transfer of the number of bytes specified in hsspicnt is com- pleted. an interrupt is generated if hsspiier.btdie is set and global interrupt is enabled. this bit is cleared by software or by hardware when the hsspicfg.hsspien is toggled (enabling or disabling the hsspi). ? bit 5 - rcvof: receive overflow bit this bit is set by hardware, when the dpram mode is set and the two 16 bytes receive buffers are full. an interrupt is generated if hsspiier.rcvofie is set and global interrupt is enabled. ? bit 4 - nssre: nss rising edge set (one) by hardware on a rising edge on hsss cleared (zero) by software ? bit 3 - nssfe: nss falling edge bit set (one) by hardware on a falling edge on hsss cleared (zero) by software 21.5.3 hsspiier - hsspi interrupt enable register ? bit 7 - timeoutie: timeout interrupt enable bit when set (one), this bit enables the timeout event as the source of the hsspi interrupt. when cleared (zero), this bit disables the timeout source of the hsspi interrupt. ? bit 6 - btdie: byte transfer done interrupt enable bit when set (one), this bit enables the byte transfer done event as the source of the hsspi interrupt. when cleared (zero), this bit disables the byte transfer done source of the hsspi interrupt. ? bit 5 - rcvofie: receive overflow interrupt enable bit when set (one), this bit enables the receive overflow event as the source of the hsspi interrupt. when cleared (zero), this bit disables the receive overflow source of the hsspi interrupt. ? bit 4 - nssie: nss interrupt enable when set (one), the hsss interrupt is enabled on falling and rising edges when cleared (zero), the hsss interrrupt is disabled bit 7 6543 2 1 0 $0000d4 timeoutie btdie rcvofie nssie - - - - hsspiier read/write r/w r/w r/w r/w r r r r initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 304 tpr0327b ? vic ? 16fev11 21.5.4 hsspicr - hsspi control register ? bit 2 - sttto: start time-out when set (one), this will rearm the time-out timer and start it once the first byte is received when cleared (zero), no action is performed. ? bit 1 - retto: rearm timeout interrupt enable bit when set (one), this will rearm the time-out timer, giving more time to receive the next byte. when cleared (zero), no action is performed. ? bit 0 - cs: spi cs bit when set (one), the hsspi hsss pin is set (one). when cleared (zero), the spi hsss pin is cleared (zero). 21.5.5 hsspisr - hsspi status register ? bit 6 - rxbufrdy: reception buffer ready bit when this bit is set (one), at least one reception buffer is full. ? bit 5 - txbuffree: transmission buffer free bit when this bit is set (one), at least one transmission buffer is empty. ? bit 4 - dpramrdy: dpram ready bit when this bit is set (one), the dpram is running and operational. when this bit is cleared (zero), the dpram is not available. ? bit 3 - nss: nss bit status of the hsss pin ? bit 2 - rxbuff: reception buffer full bit when this bit is set (one), all reception buffers are full. ? bit 1 - txbufe: transmission buffer empty bit when this bit is set (one), all transmission buffers are empty. ? bit 0 - spickrdy: spi clock ready bit when this bit is set (one), the hsspi controller is running and operational. bit 76543210 $0000db -----stttorettocsh sspicr read/writerrrrrwww initial value 0 0 0 0 0 0 0 0 0x00 bit 7 6 5 4 3 2 1 0 $0000d8 - rxbufrdy txbuffree dpramrdy nss rxbuff txbufe spickrdy hsspisr read only r r r r r r r r initial value 0 0 0 0 0 0 0 0 0x00
305 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 when this bit is cleared (zero), the hsspi controller is not available. 21.5.6 hsspitdr - hsspi transmit data register ? bits 7..0 - hsspitdd7..0: transmit data value this register is used only when the dpram mode is disabled. the hsspi transmit data register is a write register used for data transmission from the register file to the hsspi shift register. writing to the register initiates data transmission. 21.5.7 hsspirdr - hsspi received data register ? bits 7..0 - hsspirdd7..0: receive data value this register is used only when the dpram mode is disabled. the hsspi receive data register is a read regist er used for data reception to the register file from the hsspi shift register. reading this regist er causes the shift register holding the first received data to be read. 21.5.8 hsspigtr - hsspi guard time register ? bits 7..0 - hsspigtd7..0: guard time value the hsspi guard time register value is the number of hsspi clock cycles to be inserted between characters, in master mode only. 21.5.9 hsspicnt - hsspi byte count register ? bits 4..0 - hsspicntd4..0 : number of byte received or to send this register is used only when dpram mode is activated. bit 76543210 $0000d7 hsspitdd [7..0] hsspitdr read/writewwwwwwww initial value00000000 0x00 bit 76543210 $0000d6 hsspirdd [7..0] hsspirdr read/writerrrrrrrr initial value00000000 0x00 bit 76543210 $0000d5 hsspigtd [7..0] hsspigtr read/write r/wr/wr/wr/wr/wr/wr/wr/w initial value00000000 0x00 bit 76543210 $0000d3 - - - hsspicntd [4..0] hsspicnt read/write r r r r/w r/w r/w r/w r/w initial value00000000 0x00
at90scr100/116/132 306 tpr0327b ? vic ? 16fev11 writing this register specifies the number of bytes to be sent and received for the current received and transmit buffers. reading this register gives the amount of data received for the current received buffer (in this case, the current received buffer means that this buffer received the expected number of data or had a timeout). 21.5.10 hsspitimeout - hsspi timeout register ? bits 15..0 - spitimeout15..0 : communication timeout this register is used only when dpram mode is activated. it specifies the number of clock cycles before a timeout occurs (bit hsspiir.timeout is set). see ?hsspiir - hsspi interrupt register? on page 302. the clock is defined by hsspicfg.spickdiv bits. see ?hsspicfg - hsspi config register? on page 301. 21.6 hsspidma controller the hsspidma controller, implemented on the at90scr100/116/132, is intended to execute fast transfers between the ram memory and the internal hsspi dpram. this feature allows the application software of the at90scr100/116/132 to manage the exchanges imposed by the spi communication at high frequency. the hsspidma is enabled as soon as dpram mode is activated (by setting bit hsspicfg.dpram). one hsspidma operation can transfer up to n bytes in (n+1) 8/16-bit risc cpu cycles. note note writing hsspicnt register will internally switch the dpram buffers. thus, the dma controller will point to the other dpram buffer. bit 1514131211 10 9 8 $0000d2 spitimeout[15..8] hsspitoh $0000d1 spitimeout [7..0] hsspitol bit 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 value 0 0 0 0 0 0 0 0 0x00 00000 0 00 0x00 caution ! all the registers described in this section cannot be accessed if the hsspi module is not enabled.
307 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 figure 21-11. hsspidma controller diagram 21.6.1 hsspidmacs - hsspidma control and status register this is the control and status register of the hsspidma controller. ? bit 2 - hsspidmaerr : dma error bit when starting the hsspidma controller, this bit is cleared (zero) by the hardware if the values in hsspidmadh, hsspidmadl and hsspidmab registers are suitable for the hsspidma operation requested. this bit can also be cleared(zero) by software. this bit is set (one) by hardware when starting a hsspidma operation and whenever one of these following cases occurs: ? the base address contained in the registers hsspidmadh and hsspidmadl is incorrect (out of the allowed range). ? according to the values of the registers hsspidmadh, hsspidmadl and hsspidmab and even if the base address is correct, an address out of the allowed range is going to be reached. note note when a hsspidma operation is started, t he 8/16-bit risc cpu is automatically stopped. at the end of the hsspidma operation, the application software auto- matically restarts where it left (actually with the instruction following the launching of the hsspidma operation). thus the application software does not need to wait for an interrupt or to need poll the end of the hsspidma operation. ram reception dpram automatic switch $100 $10ff 16 bytes 16 bytes hsspidmacs.dmar 0 1 hsspidmacs.dmadir 0 1 dmab hsspidmacs.dmaerr dmad dma controller diagram transmission dpra automatic switch 16 bytes 16 bytes hsspidmacs.dmar 0 1 bit 7 6 5 4 3 2 1 0 $0000dc - - - - - hsspidmaerr hsspidmadir hsspidmar hsspidmacs read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 308 tpr0327b ? vic ? 16fev11 ? the value in the register hsspidmab is greater than the size of the dpram (16bytes) for the hsspidma operation. when this bit is set, and if the hsspi interruptions are enabled, an hsspi interruption is generated. ? bit 1- hsspidmadir: dma direction bit: this bit is set (one) and cleared (zero) by software. it indicates the direction of the next hsspidma operation transfer between the ram memory and the internal dpram of hsspi block. ? if the bit is set (one), the transfer will be from the ram memory to the current transmission dpram (emission mode). the empty transmission dpram will be automatically selected. ? if the bit is cleared (zero), the transfer will be from the current reception dpram to the ram memory (receiving mode). the firstly filled dpram will be selected before the other (more recently modified). ? bit 0 - hsspidmar: dma run bit: this bit is set (one) by software and cleared (zero) by hardware. this bit controls the hsspidma operation launching. it is set (one) by software when a hsspidma operation is to be performed. it is cleared (zero) by hardware at the end of the operation. caution ! don?t forget to clear the hsspidmacs. dmaerr bit before leaving the interrup- tion routine to avoid repetitive and endless interruptions. note note the software does not need to poll this bit in order to detect the end of the hsspi- dma operation. indeed, when the hsspidmacs.dmar bit is set by the software, the 8/16-bit risc cpu is automatically stopped. when the end of the hssspi- dma operation is reached, the 8/16-bit risc cpu then automatically executes the instructions following the setting of the bit hsspidmacs.dmar. note note a hsspidma operation can not be interrupted because the cpu is not available during this time.
309 tpr0327b ? vic ? 16fev11 21. high-speed spi controller at90scr100/116/132 21.6.2 hsspidmad - hsspidma address registers ? bits 7..6 - res: reserved bits these bits are reserved bits in the at90scr100/116/132 and are always read as zero. ? bits 13..0 - hsspidmad13..0 : hs spi dma address these bits represents the 14-bit hsspidma address. these two registers set the base address in ram. this address represents the source of the data to be sent if the hsspidma controller is configured in the emission mode. it represents the destination to store the data if the hsspidma controller is configured in the receiving mode. the initial value corresponds to ram address $000100. you can address the whole ram with this parameter. values in ram that must not be dumped, shall be stored out of the hsspidma ram accessible range. when starting a hsspidma operation, the hardware will check if the values of hsspidmadh, hsspidmadl and hsspidmab registers does not exceed the specific ram area ($000100 to $0010ff). if an error is detected, hsspidmacs.dmaerr bit is automatically set (one). a supervisor ram illegal access attempt violation security interrupt (if not masked) is so trig- gered. hsspidmadh, hsspidmadl and hsspidmab registers keep their previous value. 21.6.3 hsspidmab - dma amount of bytes register this register is dedicated to the amount of bytes to be transferred during the next hsspidma operation setting. ? bit 7..5 - res : reserved bits this bit is reserved bit in the at90scr100/116/132 and is always read as zero. bit 15 1413121110 9 8 $0000de - - hsspidmad [13..8] hsspidmadh $0000dd hsspidmad [8..0] hsspidmadl bit 7 6 5 4 3 2 1 0 read/write r r 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 1 0x01 0 0 0 0 0 0 0 0 0x00 note note after a hsspidma operation, hsspidmadh and hsspidmadl are set to the last value reached in ram and incremented by one. for instance, after a 64-byte transfer started from base address $000100, hsspidmad equals to $000140 (hsspidmadh = $01 and hsspidmadl = $40). this feature allows to simplify registers and bits handlings when several hsspidma operations are to be suc- cessively performed, which can be the case when getting or sending several packets. bit 76543 2 10 $00df - - - hsspidmab [4..0] hsspidmab 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 0x00
at90scr100/116/132 310 tpr0327b ? vic ? 16fev11 ? bits 4..0 - hsspidmab4..0 : hs spi dma amount of bytes bits these bits are the (4..0) bits of the 7-bit hsspidma amount of bytes value. when starting a hsspidma operation, the hardware will check if the values of hsspidmadh, hsspidmadl and hsspidmab registers does not exceed the specific ram area ($000100 to $0010ff). if an error is detected, hsspidmacs.dmaerr bit is automatically set (one). a supervisor ram illegal access attempt violation security interrupt (if not masked) is so trig- gered. hsspidmadh, hsspidmadl and hsspidmab registers keep their previous value. note note after a hsspidma operation completion, the value of this register is not reset. the maximum value allowed for hsspidmab is 16.
311 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 22. 2-wire serial interface _ twi 22.1 features ? simple yet powerful and flexible communication interface, only two bus lines needed ? both master and slave operation supported ? device can operate as transmitter or receiver ? 7-bit address space allows up to 128 different slave addresses ? multi-master arbitration support ? up to 400 khz data transfer speed ? slew-rate limited output drivers ? noise suppression circuitry rejects spikes on bus lines ? fully programmable slave addre ss with general call support ? address recognition causes wake-up when 8/16-bit risc cpu is in sleep mode 22.2 twi serial interface bus definition the 2-wire serial interface (twi) is ideally suited for typical microcontroller applications. the twi protocol allows the systems designer to interconnect up to 128 different devices using only two bi-directional bus lines, one for clock (scl) and one for data (sda). the only external hard- ware needed to implement the bus is a single pull-up resistor for each of the twi bus lines. all devices connected to the bus have individual addresses, and mechanisms for resolving bus contention are inherent in the twi protocol. figure 22-1. twi bus interconnection 22.2.1 twi terminology the following definitions are frequently encountered in this section. device 1 device 2 device 3 device n sda scl ........ r1 r2 v cc table 22-1. twi terminology term description master the device that initiates and terminates a transmission. the master also generates the scl clock.
at90scr100/116/132 312 tpr0327b ? vic ? 16fev11 the power reduction twi bit, prtwi bit in prr0 must be written to zero to enable the twi serial interface. 22.2.2 electrical interconnection the number of devices that can be connected to the bus is only limited by the bus capacitance- limit of 400 pf and the 7-bit slave address sp ace. a detailed specific ation of the electrical characteristics of the twi is given in section ?2-wire serial interface characteristics? on page 424 . two different sets of specifications are presented there, one relevant for bus speeds below 100 khz, and one valid for bus speeds up to 400 khz. 22.3 data transfer and frame format 22.3.1 transferring bits each data bit transferred on the twi bus is accompanied by a pulse on the clock line. the level of the data line must be stable when the clock line is high. the only exception to this rule is for generating start and stop conditions. figure 22-2. data validity 22.3.2 start and stop conditions the master initiates and terminates a data transmission. the transmission is initiated when the master issues a start condition on the bus, a nd it is terminated when the master issues a stop condition. between a start and a stop condition, the bus is considered busy, and no other master should try to seize control of t he bus. a special case occurs when a new start condition is issued between a start and stop condition. this is referred to as a repeated start condition, and is used when the master wishes to initiate a new transfer without relin- quishing control of the bus. after a repeated start, the bus is considered busy until the next stop. this is identical to the start behavior, and therefore start is used to describe both start and repeated start for the remainder of this datasheet, unless otherwise noted. as depicted below, start and stop conditions are signalled by changing the level of the sda line when the scl line is high. slave the device addressed by a master. transmitter the device placing data on the bus. receiver the device reading data from the bus. table 22-1. twi terminology term description sda scl data stable data stable data change
313 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 figure 22-3. start, repeated start and stop conditions 22.3.3 address packet format all address packets transmitted on the twi bus are 9 bits long, consisting of 7 address bits, one read/write control bit and an acknowledge bit. if the read/write bit is set, a read opera- tion is to be performed, otherwise a write operation should be performed. when a slave recognizes that it is being addressed, it should acknowledge by pulling sda low in the ninth scl (ack) cycle. if the addressed slave is busy, or for some other reason can not service the mas- ter?s request, the sda line should be left high in the ack clock cycle. the master can then transmit a stop condition, or a repeated start condition to initiate a new transmission. an address packet consisting of a slave address and a read or a write bit is called sla+r or sla+w, respectively. the msb of the address byte is transmitted first. slave addresses can freely be allocated by the designer, but the address 0000 000 is reserved for a general call. when a general call is issued, all slaves should respond by pulling the sda line low in the ack cycle. a general call is used when a master wishes to transmit the same message to several slaves in the system. when the general call address followed by a write bit is transmitted on the bus, all slaves set up to acknowledge the general call will pull the sda line low in the ack cycle. the following data packets will then be received by all the slaves that acknowledged the general call. note that transmitting the general call addr ess followed by a read bit is meaningless, as this would cause contention if several slaves started transmitting different data. all addresses of the format 1111 xxx should be reserved for future purposes. figure 22-4. address packet format 22.3.4 data packet format all data packets transmitted on the twi bus are nine bits long, consisting of one data byte and an acknowledge bit. during a data transfer, the master generates the clock and the start and sda scl start stop repeated start stop start sda scl start 12 789 addr msb addr lsb r/w ack
at90scr100/116/132 314 tpr0327b ? vic ? 16fev11 stop conditions, while the receiver is responsible for acknowledging the reception. an acknowledge (ack) is signalled by the receiver pulling the sda line low during the ninth scl cycle. if the receiver leaves the sda line high, a nack is signalled. when the receiver has received the last byte, or for some reason cannot receive any more bytes, it should inform the transmitter by sending a nack after the final byte. the msb of the data byte is transmitted first. figure 22-5. data packet format 22.3.5 combining address and data packets into a transmission a transmission basically consists of a start condition, a sla+r/w, one or more data packets and a stop condition. an empty message, consisting of a start followed by a stop condi- tion, is illegal. note that the wired-anding of the scl line can be used to implement handshaking between the master and the slave. the slave can extend the scl low period by pulling the scl line low. this is useful if the clock speed set up by the master is too fast for the slave, or the slave needs extra time for processing between the data transmissions. the slave extending the scl low period will not affect the scl high period, which is determined by the master. as a consequence, the slave can reduce the twi data transfer speed by prolonging the scl duty cycle. figure 22-6 shows a typical data transmission. note that several data bytes can be transmitted between the sla+r/w and the stop condition, depending on the software protocol imple- mented by the application software. figure 22-6. typical data transmission 12 789 data msb data lsb ack aggregate sda sda from transmitter sda from receiver scl from master sla+r/w data byte stop, repeated start or next data byte 12 789 data byte data msb data lsb ack a l start 12 789 addr msb addr lsb r/w ack sla+r/w st
315 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 22.4 multi-master bus systems, arbitration and synchronization the twi protocol allows bus systems with several masters. special concerns have been taken in order to ensure that transmissions will proceed as normal, even if two or more masters initiate a transmission at the same time. two problems arise in multi-master systems: ? an algorithm must be implemented allowing only one of the masters to complete the transmission. all other masters should cease transmission when they discover that they have lost the selection process. this selection process is called arbitration. when a contending master discovers that it has lost the arbitration process, it should immediately switch to slave mode to check whether it is being addressed by the winning master. the fact that multiple masters have started transmission at the same time should not be detectable to the slaves, i.e. the data being transferred on the bus must not be corrupted. ? different masters may use different scl frequencies. a scheme must be devised to synchronize the serial clocks from all masters, in order to let the transmission proceed in a lockstep fashion. this will facilitate the arbitration process. the wired-anding of the bus lines is used to solve both these problems. the serial clocks from all masters will be wired-anded, yielding a combined clock with a high period equal to the one from the master with the shortest high period. the low period of the combined clock is equal to the low period of the master with the longest low period. note that all masters listen to the scl line, effectively starting to count their scl high and low time-out periods when the combined scl line goes high or low, respectively. figure 22-7. scl synchronization between multiple masters arbitration is carried out by all masters continuously monitoring the sda line after outputting data. if the value read from the sda line does not match the value the master had output, it has lost the arbitration. note that a master can only lose arbitration when it outputs a high sda value while another master outputs a low value. the losing master should immediately go to slave mode, checking if it is being addressed by the winning master. the sda line should be left high, but losing masters are allowed to generate a clock signal until the end of the current data or address packet. arbitration will continue until only one master remains, and this may take many ta low ta high scl from master a scl from master b scl bus line tb low tb high masters start counting low period masters start counting high period
at90scr100/116/132 316 tpr0327b ? vic ? 16fev11 bits. if several masters are trying to address the same slave, arbitration will continue into the data packet. figure 22-8. arbitration between two masters note that arbitration is not allowed between: ? a repeated start condition and a data bit. ? a stop condition and a data bit. ? a repeated start and a stop condition. it is the user software?s responsibility to ensure that these illegal arbitration conditions never occur. this implies that in multi-master systems, all data transfers must use the same composi- tion of sla+r/w and data packets. in other words: all transmissions must contain the same number of data packets, otherwise the result of the arbitration is undefined. 22.5 overview of the twi module the twi module is comprised of several submodules, as shown in figure 22-9 . all registers drawn in a thick line are accessible through the 8/16-bit risc cpu data bus. sda from master a sda from master b sda line synchronized scl line start master a loses arbitration, sda a sda
317 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 figure 22-9. overview of the twi module 22.5.1 scl and sda pins these pins interface the 8/16-bit risc cpu twi with the rest of the mcu system. the output drivers contain a slew-rate limiter in order to conform to the twi specification. the input stages contain a spike suppression unit removing spikes shorter than 50 ns. note that sda and scl pads supports internal pull-ups. the internal pu ll-ups can in some systems eliminate the need for external ones. 22.5.2 bit rate generator unit this unit controls the period of scl when operating in a master mode. the scl period is con- trolled by settings in the twi bit rate register (twbr) and the prescaler bits in the twi status register (twsr). slave operation does not depend on bit rate or prescaler settings, but the cpu clock frequency in the slave must be at least 16 times higher than the scl frequency. note that slaves may prolong the scl low period, thereby reducing the average twi bus clock period. the scl frequency is generated according to the following equation: ? twbr = value of the twi bit rate register. twi unit address register (twar) address match unit address comparator control unit control register (twcr) status register (twsr) state machine and status control scl slew-rate control spike filter sda slew-rate control spike filter bit rate generator bit rate register (twbr) prescaler bus interface unit start / stop control arbitration detection ack spike suppression address/data shift register (twdr) scl frequency cpu clock frequency 16 2(twbr) 4 twps ? + ----------------------------------------------------------- =
at90scr100/116/132 318 tpr0327b ? vic ? 16fev11 ? twps = value of the prescaler bits in the twi status register 22.5.3 bus interface unit this unit contains the data and address shift register (twdr), a start/stop controller and arbitration detection hardware. the twdr contains the address or data bytes to be transmitted, or the address or data bytes received. in addition to the 8-bit twdr, the bus interface unit also contains a register containing the (n)ack bit to be transmitted or received. this (n)ack regis- ter is not directly accessible by the application software. however, when receiving, it can be set or cleared by manipulating the twi control r egister (twcr). when in transmitter mode, the value of the received (n)ack bit can be determined by the value in the twsr. the start/stop controller is responsible for generation and detection of start, repeated start, and stop conditions. the start/stop controller is able to detect start and stop conditions even when the 8/16-bit risc cpu mcu is in one of the sleep modes, enabling the mcu to wake up if addressed by a master. if the twi has initiated a transmission as master, the arbitration detection hardware continu- ously monitors the transmission trying to determine if arbitration is in process. if the twi has lost an arbitration, the control unit is informed. correct action can then be taken and appropriate status codes generated. 22.5.4 address match unit the address match unit checks if received address bytes match the seven-bit address in the twi address register (twar). if the twi general call recognition enable (twgce) bit in the twar is written to one, all incoming address bits will also be compared against the general call address. upon an address match, the control unit is informed, allowing correct action to be taken. the twi may or may not acknowledge its address, depending on settings in the twcr. the address match unit is able to compare addresses even when the 8/16-bit risc cpu mcu is in sleep mode, enabling the mcu to wake up if addressed by a master. if another interrupt (e.g., int0) occurs during twi power-down address match and wakes up the cpu, the twi aborts operation and return to its idle state. if this causes any problems, ensure that twi address match is the only enabled interrupt when entering power-down. 22.5.5 control unit the control unit monitors the twi bus and generates responses corresponding to settings in the twi control register (twcr). when an event requiring the attention of the application occurs on the twi bus, the twi interrupt flag (twint) is asserted. in the next clock cycle, the twi sta- tus register (twsr) is updated with a stat us code identifying the event. the twsr only contains relevant status information when the twi interrupt flag is asserted. at all other times, the twsr contains a special status code indicating that no relevant status information is avail- able. as long as the twint flag is set, the scl line is held low. this allows the application software to complete its tasks before allowing the twi transmission to continue. the twint flag is set in the following situations: ? after the twi has transmitted a start/repeated start condition. ? after the twi has transmitted sla+r/w. note note pull-up resistor values should be selected according to the scl frequency and the capacitive bus line load.
319 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 ? after the twi has transmitted an address byte. ? after the twi has lost arbitration. ? after the twi has been addressed by own slave address or general call. ? after the twi has received a data byte. ? after a stop or repeated start has been received while still addressed as a slave. ? when a bus error has occurred due to an illegal start or stop condition. 22.6 using the twi the 8/16-bit risc cpu twi is byte-oriented and interrupt based. interrupts are issued after all bus events, like reception of a byte or transmission of a start condition. because the twi is interrupt-based, the application software is free to carry on other operations during a twi byte transfer. note that the twi interrupt enable (twie) bit in twcr together with the global inter- rupt enable bit in sreg allow the application to decide whether or not assertion of the twint flag should generate an interrupt request. if the twie bit is cleared, the application must poll the twint flag in order to detect actions on the twi bus. when the twint flag is asserted, the twi has finished an operation and awaits application response. in this case, the twi status register (twsr) contains a value indicating the current state of the twi bus. the application software can then decide how the twi should behave in the next twi bus cycle by manipulating the twcr and twdr registers. figure 22-10 is a simple example of how the application can interface to the twi hardware. in this example, a master wishes to transmit a single data byte to a slave. this description is quite abstract, a more detailed explanation follows later in this section. a simple code example imple- menting the desired behavior is also presented. figure 22-10. interfacing the application to the twi in a typical transmission 1. the first step in a twi transmission is to transmit a start condition. this is done by writing a specific value into twcr, instructing the twi hardware to transmit a start condition. the value to write is described later on. however, it is important that the twint bit is set in the value written. writing a one to twint clears the flag. the twi will not start any operation as long as the twint bit in twcr is set. immediately after start sla+w a data a stop 1. application writes to twcr to initiate transmission of start 2. twint set. status code indicates start condition sent 4. twint set. status code indicates sla+w sent, ack received 6. twint set. status code indicates data sent, ack received 3. check twsr to see if start was sent. application loads sla+w into twdr, and loads appropriate control signals into twcr, making sure that twint is written to one, and twsta is written to zero. 5. check twsr to see if sla+w was sent and ack received. application loads data into twdr, and loads appropriate control signals into twcr, making sure that twint is written to one 7. check twsr to see if data was sent and ack received. application loads appropriate control signals to send stop into twcr, making sure that twint is written to one twi bus indicates twint set application action twi hardware action
at90scr100/116/132 320 tpr0327b ? vic ? 16fev11 the application has cleared twint, the twi will initiate transmission of the start condition. 2. when the start condition has been transmitted, the twint flag in twcr is set, and twsr is updated with a status code indicating that the start condition has success- fully been sent. 3. the application software should now examine the value of twsr, to make sure that the start condition was successfully transmitted. if twsr indicates otherwise, the application software might take some special action, like calling an error routine. assuming that the status code is as expected, the application must load sla+w into twdr. remember that twdr is used both for address and data. after twdr has been loaded with the desired sla+w, a specific value must be written to twcr, instructing the twi hardware to transmit the sla+w present in twdr. which value to write is described later on. however, it is important that the twint bit is set in the value written. writing a one to twint clears the flag. the twi will not start any operation as long as the twint bit in twcr is set. immediately after the application has cleared twint, the twi will initiate transmission of the address packet. 4. when the address packet has been transmitted, the twint flag in twcr is set, and twsr is updated with a status code indicating that the address packet has success- fully been sent. the status code will also reflect whether a slave acknowledged the packet or not. 5. the application software should now examine the value of twsr, to make sure that the address packet was successfully transmitted, and that the value of the ack bit was as expected. if twsr indicates otherwise, the application software might take some special action, like calling an error routine. assuming that the status code is as expected, the application must load a data packet into twdr. subsequently, a specific value must be written to twcr, instructing the twi hardware to transmit the data packet present in twdr. which value to write is described later on. however, it is important that the twint bit is set in the value written. writing a one to twint clears the flag. the twi will not start any operation as long as the twint bit in twcr is set. immediately after the application has cleared twint, the twi will initiate transmission of the data packet. 6. when the data packet has been transmitted, the twint flag in twcr is set, and twsr is updated with a status code indicating that the data packet has successfully been sent. the status code will also reflect whether a slave acknowledged the packet or not. 7. the application software should now examine the value of twsr, to make sure that the data packet was successfully transmitted, and that the value of the ack bit was as expected. if twsr indicates otherwise, the application software might take some spe- cial action, like calling an error routine. assuming that the status code is as expected, the application must write a specific value to twcr, instructing the twi hardware to transmit a stop condition. which value to write is described later on. however, it is important that the twint bit is set in the value written. writing a one to twint clears the flag. the twi will not start any operation as long as the twint bit in twcr is set. immediately after the application has cleared twint, the twi will initiate transmission of the stop condition. note that twint is not set after a stop condition has been sent. even though this example is simple, it shows t he principles involved in all twi transmissions. these can be summarized as follows: ? when the twi has finished an operation and expects application response, the twint flag is set. the scl line is pulled low until twint is cleared.
321 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 ? when the twint flag is set, the user must update all twi registers with the value relevant for the next twi bus cycle. as an example, twdr must be loaded with the value to be transmitted in the next bus cycle. ? after all twi register updates and other pending application software tasks have been completed, twcr is written. when writing twcr, the twint bit should be set. writing a one to twint clears the flag. the twi will then start executing whatever operation was specified by the twcr setting. in the following an assembly and c implementation of the example is given. note that the code below assumes that several definitions have been made, for example by using include-files. assembly code example c example comments 1 ldi r16, (1< at90scr100/116/132 322 tpr0327b ? vic ? 16fev11 22.7 transmission modes the twi can operate in one of four major modes. these are named master transmitter (mt), master receiver (mr), slave transmitter (st) and slave receiver (sr). several of these modes can be used in the same application. as an example, the twi can use mt mode to write data into a twi eeprom, mr mode to read the data back from the eeprom. if other masters are present in the system, some of these might transmit data to the twi, and then sr mode would be used. it is the application software that decides which modes are legal. the following sections describe each of these modes. possible status codes are described along with figures detailing data transmission in each of the modes. thes e figures contain the following abbreviations: s: start condition rs: repeated start condition r: read bit (high level at sda) w: write bit (low level at sda) a: acknowledge bit (low level at sda) a : not acknowledge bit (high level at sda) data: 8-bit data byte p: stop condition sla: slave address in figure 22-12 to figure 22-18 , circles are used to indicate that the twint flag is set. the numbers in the circles show the status code held in twsr, with the prescaler bits masked to zero. at these points, actions must be taken by the application to continue or complete the twi transfer. the twi transfer is suspended until the twint flag is cleared by software. when the twint flag is set, the status code in twsr is used to determine the appropriate soft- ware action. for each status code, the required software action and details of the following serial transfer are given in table 22-2 to table 22-4 . note that the prescaler bits are masked to zero in these tables. 6 wait3: in r16,twcr sbrs r16,twint rjmp wait3 while (!(twcr & (1< 323 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 22.7.1 master transmitter mode in the master transmitter mode, a number of data bytes are transmitted to a slave receiver (see figure 22-11 ). in order to enter a master mode, a start condition must be transmitted. the format of the following address packet determines whether master transmitter or master receiver mode is to be entered. if sla+w is transmitted, mt mode is entered, if sla+r is trans- mitted, mr mode is entered. all the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. figure 22-11. data transfer in master transmitter mode a start condition is sent by writing the following value to twcr: twen must be set to enable the 2-wire serial interface, twsta must be written to one to trans- mit a start condition and twint must be written to one to clear the twint flag. the twi will then test the 2-wire serial bus and generate a start condition as soon as the bus becomes free. after a start condition has been transmitted, the twint flag is set by hardware, and the status code in twsr will be 0x08 (see table 22-2 ). in order to enter mt mode, sla+w must be transmitted. this is done by writing sla+w to twdr. thereafter the twint bit should be cleared (by writing it to one) to continue the transfer. this is accomplished by writing the follow- ing value to twcr: when sla+w have been transmitted and an acknowledgement bit has been received, twint is set again and a number of status codes in twsr are possible. possible status codes in master mode are 0x18, 0x20, or 0x38. the appropriate action to be taken for each of these status codes is detailed in table 22-2 . when sla+w has been successfully transmitted, a data packet should be transmitted. this is done by writing the data byte to twdr. twdr must only be written when twint is high. if not, note note please note that r1 and r2 resistors may not be required. the internal pull-up resistors on sda and scl pads of 8/16-bit risc cpu may be sufficient to setup a communication. however, if the edges are not strong enough to get a clean sig- nals, r1 and r2 can be added. twcr twint twea twsta twsto twwc twen ? twie value 1 x10 x1 0 x twcr twint twea twsta twsto twwc twen ? twie value 1 x00 x1 0 x device 1 master transmitter device 2 slave receiver device 3 device n sda scl ........ r1 r2 v cc
at90scr100/116/132 324 tpr0327b ? vic ? 16fev11 the access will be discarded, and the write collision bit (twwc) will be set in the twcr regis- ter. after updating twdr, the twint bit should be cleared (by writing it to one) to continue the transfer. this is accomplished by writing the following value to twcr: this scheme is repeated until the last byte has been sent and the transfer is ended by generat- ing a stop condition or a repeated start condition. a stop condition is generated by writing the following value to twcr: a repeated start condition is generated by writing the following value to twcr: after a repeated start condition (state 0x10) the 2-wire serial interface can access the same slave again, or a new slave without transmitting a stop condition. repeated start enables the master to switch between slaves, master transmitter mode and master receiver mode with- out losing control of the bus. twcr twint twea twsta twsto twwc twen ? twie value 1 x00 x1 0 x twcr twint twea twsta twsto twwc twen ? twie value 1 x01 x1 0 x twcr twint twea twsta twsto twwc twen ? twie value 1 x10 x1 0 x table 22-2. status codes for master transmitter mode status code (twsr) prescaler bits are 0 status of the 2-wire serial bus and 2-wire serial interface hardware application software response next action taken by twi hardware to/from twdr to twcr sta sto twin t twea 0x08 a start condition has been transmitted load sla+w 0 0 1 x sla+w will be transmitted; ack or not ack will be received 0x10 a repeated start condition has been transmitted load sla+w or load sla+r 0 0 0 0 1 1 x x sla+w will be transmitted; ack or not ack will be received sla+r will be transmitted; logic will switch to master receiver mode 0x18 sla+w has been transmitted; ack has been received load data byte or no twdr action or no twdr action or no twdr action 0 1 0 1 0 0 1 1 1 1 1 1 x x x x data byte will be transmitted and ack or not ack will be received repeated start will be transmitted stop condition will be transmitted and twsto flag will be reset stop condition followed by a start condition will be transmitted and twsto flag will be reset 0x20 sla+w has been transmitted; not ack has been received load data byte or no twdr action or no twdr action or no twdr action 0 1 0 1 0 0 1 1 1 1 1 1 x x x x data byte will be transmitted and ack or not ack will be received repeated start will be transmitted stop condition will be transmitted and twsto flag will be reset stop condition followed by a start condition will be transmitted and twsto flag will be reset
325 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 0x28 data byte has been transmit- ted; ack has been received load data byte or no twdr action or no twdr action or no twdr action 0 1 0 1 0 0 1 1 1 1 1 1 x x x x data byte will be transmitted and ack or not ack will be received repeated start will be transmitted stop condition will be transmitted and twsto flag will be reset stop condition followed by a start condition will be transmitted and twsto flag will be reset 0x30 data byte has been transmit- ted; not ack has been received load data byte or no twdr action or no twdr action or no twdr action 0 1 0 1 0 0 1 1 1 1 1 1 x x x x data byte will be transmitted and ack or not ack will be received repeated start will be transmitted stop condition will be transmitted and twsto flag will be reset stop condition followed by a start condition will be transmitted and twsto flag will be reset 0x38 arbitration lost in sla+w or data bytes no twdr action or no twdr action 0 1 0 0 1 1 x x 2-wire serial bus will be released and not ad- dressed slave mode entered a start condition will be transmitted when the bus becomes free table 22-2. status codes for master transmitter mode
at90scr100/116/132 326 tpr0327b ? vic ? 16fev11 figure 22-12. formats and states in the master transmitter mode 22.7.2 master receiver mode in the master receiver mode, a number of data bytes are received from a slave transmitter (slave see figure 22-13 ). in order to enter a master mode, a start condition must be transmit- ted. the format of the following address packet determines whether master transmitter or master receiver mode is to be entered. if sla+w is transmitted, mt mode is entered, if sla+r is transmitted, mr mode is entered. all the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. s sla w a data a p $08 $18 $28 r sla w $10 ap $20 p $30 a or a $38 a other master continues a or a $38 other master continues r a $68 other master continues $78 $b0 to corresponding states in slave mode mt mr successfull transmission to a slave receiver next transfer started with a repeated start condition not acknowledge received after the slave address not acknowledge received after a data byte arbitration lost in slave address or data byte arbitration lost and addressed as slave data a n from master to slave from slave to master any number of data bytes and their associated acknowledge bits this number (contained in twsr) corresponds to a defined state of the two-wire serial bus. the prescaler bits are zero or masked to zero s
327 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 figure 22-13. data transfer in master receiver mode a start condition is sent by writing the following value to twcr: twen must be written to one to enable the 2-wire serial interface, twsta must be written to one to transmit a start condition and twint must be set to clear the twint flag. the twi will then test the 2-wire serial bus and generate a start condition as soon as the bus becomes free. after a start condition has been transmitted, the twint flag is set by hard- ware, and the status code in twsr will be 0x08 (see table 22-2 ). in order to enter mr mode, sla+r must be transmitted. this is done by writing sla+r to twdr. thereafter the twint bit should be cleared (by writing it to one) to continue the transfer. this is accomplished by writing the following value to twcr: when sla+r have been transmitted and an acknowledgement bit has been received, twint is set again and a number of status codes in twsr are possible. possible status codes in master mode are 0x38, 0x40, or 0x48. the appropriate action to be taken for each of these status codes is detailed in table 22-3 . received data can be read from the twdr register when the twint flag is set high by hardware. this scheme is repeated until the last byte has been received. after the last byte has been received, the mr should inform the st by sending a nack after the last received data byte. the transfer is ended by generating a stop condition or a repeated start condition. a stop condition is generated by writing the following value to twcr: a repeated start condition is generated by writing the following value to twcr: note note please note that r1 and r2 resistors may be useless. indeed, internal pull-up resistors on sda and scl pads of 8/16-bit risc cpu may be sufficient to setup a communication. anyway, r1 and r2 are welcomed if the edges are not strong enough to get a clean signals. twcr twint twea twsta twsto twwc twen ? twie value 1 x10 x1 0 x twcr twint twea twsta twsto twwc twen ? twie value 1 x00 x1 0 x twcr twint twea twsta twsto twwc twen ? twie value 1 x01 x1 0 x twcr twint twea twsta twsto twwc twen ? twie device 1 master receiver device 2 slave transmitter device 3 device n sda scl ........ r1 r2 v cc
at90scr100/116/132 328 tpr0327b ? vic ? 16fev11 after a repeated start condition (state 0x10) the 2-wire serial interface can access the same slave again, or a new slave without transmitting a stop condition. repeated start enables the master to switch between slaves, master transmitter mode and master receiver mode with- out losing control over the bus. value 1 x10 x1 0 x table 22-3. status codes for master receiver mode status code (twsr) prescaler bits are 0 status of the 2-wire serial bus and 2-wire serial interface hardware application software response next action taken by twi hardware to/from twdr to twcr sta sto twin t twe a 0x08 a start condition has been transmitted load sla+r 0 0 1 x sla+r will be transmitted ack or not ack will be received 0x10 a repeated start condition has been transmitted load sla+r or load sla+w 0 0 0 0 1 1 x x sla+r will be transmitted ack or not ack will be received sla+w will be transmitted logic will switch to master transmitter mode 0x38 arbitration lost in sla+r or not ack bit no twdr action or no twdr action 0 1 0 0 1 1 x x 2-wire serial bus will be released and not addressed slave mode will be entered a start condition will be transmitted when the bus becomes free 0x40 sla+r has been transmitted; ack has been received no twdr action or no twdr action 0 0 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be returned 0x48 sla+r has been transmitted; not ack has been received no twdr action or no twdr action or no twdr action 1 0 1 0 1 1 1 1 1 x x x repeated start will be transmitted stop condition will be transmitted and twsto flag will be reset stop condition followed by a start condition will be transmitted and twsto flag will be reset 0x50 data byte has been received; ack has been returned read data byte or read data byte 0 0 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be returned 0x58 data byte has been received; not ack has been returned read data byte or read data byte or read data byte 1 0 1 0 1 1 1 1 1 x x x repeated start will be transmitted stop condition will be transmitted and twsto flag will be reset stop condition followed by a start condition will be transmitted and twsto flag will be reset
329 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 figure 22-14. formats and states in the master receiver mode 22.7.3 slave receiver mode in the slave receiver mode, a number of data bytes are received from a master transmitter (see figure 22-15 ). all the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. s sla r a data a $08 $40 $50 sla r $10 ap $48 a or a $38 other master continues $38 other master continues w a $68 other master continues $78 $b0 to corresponding states in slave mode mr mt successfull reception from a slave receiver next transfer started with a repeated start condition not acknowledge received after the slave address arbitration lost in slave address or data byte arbitration lost and addressed as slave data a n from master to slave from slave to master any number of data bytes and their associated acknowledge bits this number (contained in twsr) corresponds to a defined state of the two-wire serial bus. the prescaler bits are zero or masked to zero p data a $58 a r s
at90scr100/116/132 330 tpr0327b ? vic ? 16fev11 figure 22-15. data transfer in slave receiver mode to initiate the slave receiver mode, twar and twcr must be initialized as follows: the upper 7 bits are the address to which the 2-wire se rial interface will respond when addressed by a master. if the lsb is set, the twi will respond to the general call address (0x00), otherwise it will ignore the general call address. twen must be written to one to enable the twi. the twea bit must be written to one to enable the acknowledgement of the device?s own slave address or the general call address. twsta and twsto must be written to zero. when twar and twcr have been initialized, the twi waits until it is addressed by its own slave address (or the general call address if en abled) followed by the data direction bit. if the direction bit is ?0? (write), the twi will operate in sr mode, otherwise st mode is entered. after its own slave address and the write bit have been received, the twint flag is set and a valid status code can be read from twsr. the status code is used to determine the appropriate soft- ware action. the appropriate action to be taken for each status code is detailed in table 22-4 . the slave receiver mode may also be entered if arbitration is lost while the twi is in the master mode (see states 0x68 and 0x78). if the twea bit is reset during a transfer, the twi will return a ?not acknowledge? (?1?) to sda after the next received data byte. this can be used to indicate that the slave is not able to receive any more bytes. while twea is zero, the twi does not acknowledge its own slave address. however, the 2-wire serial bus is still monitored and address recognition may resume at any time by setting twea. this implies that the twea bit may be used to temporarily isolate the twi from the 2-wire serial bus. in all sleep modes other than idle mode, the clock system to the twi is turned off. if the twea bit is set, the interface can still acknowledge its own slave address or the general call address by using the 2-wire serial bus clock as a clock source. the part will then wake up from sleep and note note please note that r1 and r2 resistors may be useless. indeed, internal pull-up resistors on sda and scl pads of 8/16-bit risc cpu may be sufficient to setup a communication. anyway, r1 and r2 are welcomed if the edges are not strong enough to get a clean signals. twar twa6 twa5 twa4 twa3 twa2 twa1 twa0 twgce value device?s own slave address twcr twint twea twsta twsto twwc twen ? twie value 0 100 01 0 x device 3 device n sda scl ........ r1 r2 v cc device 2 master transmitter device 1 slave receiver
331 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 the twi will hold the scl clock low during the wake up and until the twint flag is cleared (by writing it to one). further data reception will be carried out as normal, with the 8/16-bit risc cpu clocks running as normal. observe that if the 8/16-bit risc cpu is set up with a long start- up time, the scl line may be held low for a long time, blocking other data transmissions. caution ! thetwi serial interface data register ? twdr does not reflect the last byte pres- ent on the bus when waking up from these sleep modes. status code (twsr) prescaler bits are 0 status of the 2-wire serial bus and 2-wire serial interface hard- ware application software response next action taken by twi hardware to/from twdr to twcr sta sto twin t twe a 0x60 own sla+w has been received; ack has been returned no twdr action or no twdr action x x 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be re- turned 0x68 arbitration lost in sla+r/w as master; own sla+w has been received; ack has been returned no twdr action or no twdr action x x 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be re- turned 0x70 general call address has been received; ack has been returned no twdr action or no twdr action x x 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be re- turned 0x78 arbitration lost in sla+r/w as master; general call address has been received; ack has been returned no twdr action or no twdr action x x 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be re- turned 0x80 previously addressed with own sla+w; data has been received; ack has been returned read data byte or read data byte x x 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be re- turned 0x88 previously addressed with own sla+w; data has been received; not ack has been returned read data byte or read data byte or read data byte or read data byte 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 1 switched to the not addressed slave mode; no recognition of own sla or gca switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1? switched to the not addressed slave mode; no recognition of own sla or gca; a start condition will be transmitted when the bus becomes free switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1?; a start condition will be transmitted when the bus becomes free
at90scr100/116/132 332 tpr0327b ? vic ? 16fev11 0x90 previously addressed with general call; data has been re- ceived; ack has been returned read data byte or read data byte x x 0 0 1 1 0 1 data byte will be received and not ack will be returned data byte will be received and ack will be re- turned 0x98 previously addressed with general call; data has been received; not ack has been returned read data byte or read data byte or read data byte or read data byte 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 1 switched to the not addressed slave mode; no recognition of own sla or gca switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1? switched to the not addressed slave mode; no recognition of own sla or gca; a start condition will be transmitted when the bus becomes free switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1?; a start condition will be transmitted when the bus becomes free 0xa0 a stop condition or repeated start condition has been received while still addressed as slave no action 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 1 switched to the not addressed slave mode; no recognition of own sla or gca switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1? switched to the not addressed slave mode; no recognition of own sla or gca; a start condition will be transmitted when the bus becomes free switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1?; a start condition will be transmitted when the bus becomes free
333 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 figure 22-16. formats and states in the slave receiver mode 22.7.4 slave transmitter mode in the slave transmitter mode, a number of data bytes are transmitted to a master receiver (see figure 22-17 ). all the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. s sla w a data a $60 $80 $88 a $68 reception of the own slave address and one or more data bytes. all are acknowledged last data byte received is not acknowledged arbitration lost as master and addressed as slave reception of the general call address and one or more data bytes last data byte received is not acknowledged n from master to slave from slave to master any number of data bytes and their associated acknowledge bits this number (contained in twsr) corresponds to a defined state of the two-wire serial bus. the prescaler bits are zero or masked to zero p or s data a $80 $a0 p or s a a data a $70 $90 $98 a $78 p or s data a $90 $a0 p or s a general call arbitration lost as master and addressed as slave by general call data a
at90scr100/116/132 334 tpr0327b ? vic ? 16fev11 figure 22-17. data transfer in slave transmitter mode to initiate the slave transmitter mode, twar and twcr must be initialized as follows: the upper seven bits are the address to which the 2-wire serial interface will respond when addressed by a master. if the lsb is set, the twi will respond to the general call address (0x00), otherwise it will ignore the general call address. twen must be written to one to enable the twi. the twea bit must be written to one to enable the acknowledgement of the device?s own slave address or the general call address. twsta and twsto must be written to zero. when twar and twcr have been initialized, the twi waits until it is addressed by its own slave address (or the general call address if en abled) followed by the data direction bit. if the direction bit is ?1? (read), the twi will operate in st mode, otherwise sr mode is entered. after its own slave address and the write bit have been received, the twint flag is set and a valid status code can be read from twsr. the status code is used to determine the appropriate soft- ware action. the appropriate action to be taken for each status code is detailed in table 22-4 . the slave transmitter mode may also be entered if arbitration is lost while the twi is in the master mode (see state 0xb0). if the twea bit is written to zero during a transfer , the twi will transmit the last byte of the trans- fer. state 0xc0 or state 0xc8 will be ent ered, depending on whether the master receiver transmits a nack or ack after the final byte. the twi is switched to the not addressed slave mode, and will ignore the master if it continues the transfer. thus the master receiver receives all ?1? as serial data. state 0xc8 is enter ed if the master demands additional data bytes (by transmitting ack), even though the slave has transmitted the last byte (twea zero and expect- ing nack from the master). while twea is zero, the twi does not respond to its own slave address. however, the 2-wire serial bus is still monitored and address recognition may resume at any time by setting twea. this implies that the twea bit may be used to temporarily isolate the twi from the 2-wire serial bus. in all sleep modes other than idle mode, the clock system to the twi is turned off. if the twea bit is set, the interface can still acknowledge its own slave address or the general call address by twar twa6 twa5 twa4 twa3 twa2 twa1 twa0 twgce value device?s own slave address twcr twint twea twsta twsto twwc twen ? twie value 0 100 01 0 x device 3 device n sda scl ........ r1 r2 v cc device 2 master receiver device 1 slave transmitter
335 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 using the 2-wire serial bus clock as a clock source. the part will then wake up from sleep and the twi will hold the scl clock will low during the wake up and until the twint flag is cleared (by writing it to one). further data transmission will be carried out as normal, with the 8/16-bit risc cpu clocks running as normal. observe that if the 8/16-bit risc cpu is set up with a long start-up time, the scl line may be held low for a long time, blocking other data transmissions. note that the 2-wire serial interface data register ? twdr does not reflect the last byte present on the bus when waking up from these sleep modes. table 22-4. status codes for slave transmitter mode status code (twsr) prescaler bits are 0 status of the 2-wire serial bus and 2-wire serial interface hard- ware application software response next action taken by twi hardware to/from twdr to twcr sta sto twin t twe a 0xa8 own sla+r has been received; ack has been returned load data byte or load data byte x x 0 0 1 1 0 1 last data byte will be transmitted and not ack should be received data byte will be transmitted and ack should be re- ceived 0xb0 arbitration lost in sla+r/w as master; own sla+r has been received; ack has been returned load data byte or load data byte x x 0 0 1 1 0 1 last data byte will be transmitted and not ack should be received data byte will be transmitted and ack should be re- ceived 0xb8 data byte in twdr has been transmitted; ack has been received load data byte or load data byte x x 0 0 1 1 0 1 last data byte will be transmitted and not ack should be received data byte will be transmitted and ack should be re- ceived 0xc0 data byte in twdr has been transmitted; not ack has been received no twdr action or no twdr action or no twdr action or no twdr action 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 1 switched to the not addressed slave mode; no recognition of own sla or gca switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1? switched to the not addressed slave mode; no recognition of own sla or gca; a start condition will be transmitted when the bus becomes free switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1?; a start condition will be transmitted when the bus becomes free 0xc8 last data byte in twdr has been transmitted (twea = ?0?); ack has been received no twdr action or no twdr action or no twdr action or no twdr action 0 0 1 1 0 0 0 0 1 1 1 1 0 1 0 1 switched to the not addressed slave mode; no recognition of own sla or gca switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1? switched to the not addressed slave mode; no recognition of own sla or gca; a start condition will be transmitted when the bus becomes free switched to the not addressed slave mode; own sla will be recognized; gca will be recognized if twgce = ?1?; a start condition will be transmitted when the bus becomes free
at90scr100/116/132 336 tpr0327b ? vic ? 16fev11 figure 22-18. formats and states in the slave transmitter mode 22.7.5 miscellaneous states there are two status codes that do not correspond to a defined twi state, see table 22-5 . status 0xf8 indicates that no relevant inform ation is available because the twint flag is not set. this occurs between other states, and when the twi is not involved in a serial transfer. status 0x00 indicates that a bus error has occu rred during a 2-wire serial bus transfer. a bus error occurs when a start or stop condition occurs at an illegal position in the format frame. examples of such illegal positions are during the serial transfer of an address byte, a data byte, or an acknowledge bit. when a bus error occurs, twint is set. to recover from a bus error, the twsto flag must set and twint must be cleared by writing a logic one to it. this causes the twi to enter the not addressed slave mode and to clear the twsto flag (no other bits in twcr are affected). the sda and scl lines are released, and no stop condition is transmitted. 22.7.6 combining several twi modes in some cases, several twi modes must be combined in order to complete the desired action. consider for example reading dat a from a serial eeprom. typically, such a transfer involves the following steps: s sla r a data a $a8 $b8 a $b0 reception of the own slave address and one or more data bytes last data byte transmitted. switched to not addressed slave (twea = '0') arbitration lost as master and addressed as slave n from master to slave from slave to master any number of data bytes and their associated acknowledge bits this number (contained in twsr) corresponds to a defined state of the two-wire serial bus. the prescaler bits are zero or masked to zero p or s data $c0 data a a $c8 p or s all 1's a table 22-5. miscellaneous states status code (twsr) prescaler bits are 0 status of the 2-wire serial bus and 2-wire serial interface hardware application software response next action taken by twi hardware to/from twdr to twcr sta sto twin t twe a 0xf8 no relevant state information available; twint = ?0? no twdr action no twcr action wait or proceed current transfer 0x00 bus error due to an illegal start or stop condition no twdr action 0 1 1 x only the internal hardware is affected, no stop condi- tion is sent on the bus. in all cases, the bus is released and twsto is cleared.
337 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 1. the transfer must be initiated. 2. the eeprom must be instructed what location should be read. 3. the reading must be performed. 4. the transfer must be finished. note that data is transmitted both from master to slave and vice versa. the master must instruct the slave what location it wants to read, requiring the use of the mt mode. subsequently, data must be read from the slave, implying the use of the mr mode. thus, the transfer direction must be changed. the master must keep control of the bus during all these steps, and the steps should be carried out as an atomical operation. if this principle is violated in a multimaster sys- tem, another master can alter the data pointer in the eeprom between steps 2 and 3, and the master will read the wrong data location. such a change in transfer direction is accomplished by transmitting a repeated start between the transmission of the address byte and reception of the data. after a repeated start, the master keeps ownership of the bus. the following figure shows the flow in this transfer. figure 22-19. combining several twi modes to access a serial eeprom 22.8 multi-master systems and arbitration if multiple masters are connected to the same bus, transmissions may be initiated simultane- ously by one or more of them. the twi standard ensures that such situations are handled in such a way that one of the masters will be allowed to proceed with the transfer, and that no data will be lost in the process. an example of an arbitration situation is depicted below, where two masters are trying to transmit data to a slave receiver. figure 22-20. an arbitration example several different scenarios may arise during arbitration, as described below: master transmitter master receiver s = start rs = repeated start p = stop transmitted from master to slave transmitted from slave to master s sla+w a address a rs sla+r a data a p device 1 master transmitter device 2 master transmitter device 3 slave receiver device n sda scl ........ r1 r2 v cc
at90scr100/116/132 338 tpr0327b ? vic ? 16fev11 ? two or more masters are performing identical communication with the same slave. in this case, neither the slave nor any of the masters will know about the bus contention. ? two or more masters are accessing the same slave with different data or direction bit. in this case, arbitration will occur, either in the read/write bit or in the data bits. the masters trying to output a one on sda while another master outputs a zero will lose the arbitration. losing masters will switch to not addressed slave mode or wait until the bus is free and transmit a new start condition, depending on application software action. ? two or more masters are accessing different slaves. in this case, arbitration will occur in the sla bits. masters trying to output a one on sda while another master outputs a zero will lose the arbitration. masters losing arbitration in sla will switch to slave mode to check if they are being addressed by the winning master. if addressed, they will switch to sr or st mode, depending on the value of the read/write bit. if they are not being addressed, they will switch to not addressed slave mode or wait until the bus is free and transmit a new start condition, depending on application software action. this is summarized in figure 22-21 . possible status values are given in circles. figure 22-21. possible status codes caused by arbitration 22.9 twi register description 22.9.1 twbr ? twi bit rate register ? bits 7..0 ? twi bit rate register twbr selects the division factor for the bit rate generator. the bit rate generator is a frequency divider which generates the scl clock frequency in the master modes. see ?bit rate generator unit? on page 317 for calculating bit rates. own address / general call received arbitration lost in sla twi bus will be released and not addressed slave mode will be entered a start condition will be transmitted when the bus becomes free no arbitration lost in data direction yes write data byte will be received and not ack will be returned data byte will be received and ack will be returned last data byte will be transmitted and not ack should be received data byte will be transmitted and ack should be received read b0 68/78 38 sla start data stop bit 76543 2 10 $0000b8 twbr7 twbr6 twbr5 twbr4 twbr3 twbr2 twbr1 twbr0 twbr 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 0x00
339 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 22.9.2 twcr ? twi control register the twcr is used to control the operation of the twi. it is used to enable the twi, to initiate a master access by applying a start condition to the bus, to generate a receiver acknowledge, to generate a stop condition, and to control halting of the bus while the data to be written to the bus are written to the twdr. it also indicates a write collision if data is attempted written to twdr while the register is inaccessible. ? bit 7 ? twint: twi interrupt flag this bit is set by hardware when the twi has finished its current job and expects application software response. if the i-bit in sreg and twie in twcr are set, the mcu will jump to the twi interrupt vector. while the twint flag is set, the scl low period is stretched. the twint flag must be cleared by software by writing a logic one to it. note that this flag is not automati- cally cleared by hardware when executing the interrupt routine. also note that clearing this flag starts the operation of the twi, so all accesses to the twi address register (twar), twi sta- tus register (twsr), and twi data register (twdr) must be complete before clearing this flag. ? bit 6 ? twea: twi enable acknowledge bit the twea bit controls the generation of the acknowledge pulse. if the twea bit is written to one, the ack pulse is generated on the twi bus if the following conditions are met: 1. the device?s own slave address has been received. 2. a general call has been received, while the twgce bit in the twar is set. 3. a data byte has been received in master receiver or slave receiver mode. by writing the twea bit to zero, the device can be virtually disconnected from the 2-wire serial bus temporarily. address recognition can then be resumed by writing the twea bit to one again. ? bit 5 ? twsta: twi start condition bit the application writes the twsta bit to one when it desires to become a master on the 2-wire serial bus. the twi hardware checks if the bus is available, and generates a start condition on the bus if it is free. however, if the bus is not free, the twi waits until a stop condition is detected, and then generates a new start condition to claim the bus master status. twsta must be cleared by software when the start condition has been transmitted. ? bit 4 ? twsto: twi stop condition bit writing the twsto bit to one in master mode will generate a stop condition on the 2-wire serial bus. when the stop condition is executed on the bus, the twsto bit is cleared auto- matically. in slave mode, setting the twsto bit can be used to recover from an error condition. this will not generate a stop condition, but the twi returns to a well-defined unaddressed slave mode and releases the scl and sda lines to a high impedance state. ? bit 3 ? twwc: twi write collision flag bit 76543 2 10 $0000bc twint twea twsta twsto twwc twen ? twie twcr read/write r/w r/w r/w r/w r r/w r r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 340 tpr0327b ? vic ? 16fev11 the twwc bit is set when attempting to write to the twi data register ? twdr when twint is low. this flag is cleared by writing the twdr register when twint is high. ? bit 2 ? twen: twi enable bit the twen bit enables twi operation and activates the twi interface. when twen is written to one, the twi takes control over the i/o pins connected to the scl and sda pins, enabling the slew-rate limiters and spike filters. if this bit is written to zero, the twi is switched off and all twi transmissions are terminated, regardless of any ongoing operation. ? bit 1 ? res: reserved bit this bit is a reserved bit and will always read as zero. ? bit 0 ? twie: twi interrupt enable when this bit is written to one, and the i-bit in sreg is set, the twi interrupt request will be acti- vated for as long as the twint flag is high. 22.9.3 twsr ? twi status register ? bits 7..3 ? tws: twi status these 5 bits reflect the status of the twi logi c and the 2-wire serial bus. the different status codes are described earlier in this section. note that the value read from twsr contains both the 5-bit status value and the 2-bit prescaler value. the application designer should mask the prescaler bits to zero when checking the status bits. this makes status checking independent of prescaler setting. this approach is used in this datasheet, unless otherwise noted. ? bit 2 ? res: reserved bit this bit is reserved and will always read as zero. ? bits 1..0 ? twps: twi prescaler bits these bits can be read and written, and control the bit rate prescaler. to calculate bit rates, see ?bit rate generator unit? on page 317 . the value of twps1..0 is used in the equation. bit 76543 2 10 $0000b9 tws7 tws6 tws5 tws4 tws3 ? twps1 twps0 twsr read/writerrrrr rr/wr/w initial value 1 1 1 1 1 0 0 0 0x00 table 22-6. twi bit rate prescaler twps1 twps0 prescaler value 001 014 1016 1164
341 tpr0327b ? vic ? 16fev11 22. 2-wire serial interface _ twi at90scr100/116/132 22.9.4 twdr ? twi data register in transmit mode, twdr contains the next byte to be transmitted. in receive mode, the twdr contains the last byte received. it is writable while the twi is not in the process of shifting a byte. this occurs when the twi interrupt flag (twint) is set by hardware. note that the data regis- ter cannot be initialized by the user before the first interrupt occurs. the data in twdr remains stable as long as twint is set. while data is shifted out, data on the bus is simultaneously shifted in. twdr always contains the last byte present on the bus, except after a wake up from a sleep mode by the twi interrupt. in this case, the contents of twdr is undefined. in the case of a lost bus arbitration, no data is lost in the transition from master to slave. handling of the ack bit is controlled automatically by the twi logic, the cpu cannot access the ack bit directly. ? bits 7..0 ? twd: twi data register these eight bits constitute the next data byte to be transmitted, or the latest data byte received on the 2-wire serial bus. 22.9.5 twar ? twi (slave) address register the twar should be loaded with the 7-bit slave address (in the seven most significant bits of twar) to which the twi will respond when programmed as a slave transmitter or receiver, and not needed in the master modes. in multimaster systems, twar must be set in masters which can be addressed as slaves by other masters. the lsb of twar is used to enable recognition of the general call address (0x00). there is an associated address comparator that looks for the slave address (or general call address if enabled) in the received serial address. if a match is found, an interrupt request is generated. ? bits 7..1 ? twa: twi (slave) address register these seven bits constitute the slave address of the twi unit. ? bit 0 ? twgce: twi general call recognition enable bit if set, this bit enables the recognition of a general call given over the 2-wire serial bus. 22.9.6 twamr ? twi (slave) address mask register ? bits 7..1 ? twam: twi address mask bit 76543 2 10 $0000bb twd7 twd6 twd5 twd4 twd3 twd2 twd1 twd0 twdr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 1 1 1 1 1 1 1 1 0xff bit 76543 2 10 $0000ba twa6 twa5 twa4 twa3 twa2 twa1 twa0 twgce twar read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 1 1 1 1 1 1 1 0 0xfe bit 76543 2 10 $0000bd twam [6:0] - twamr 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 0x00
at90scr100/116/132 342 tpr0327b ? vic ? 16fev11 the twamr can be loaded with a 7-bit slave addr ess mask. each of the bits in twamr can mask (disable) the corresponding address bit in the twi address register (twar). if the mask bit is set to one then the address match logi c ignores the compare between the incoming address bit and the corresponding bit in twar. figure 22-22 shows the address match logic in detail. figure 22-22. twi address match logic, block diagram ? bit 0 ? res: reserved bit this bit is reserved and will always read as zero. address match address bit comparator 0 address bit comparator 6..1 twar0 twamr0 address bit 0
343 tpr0327b ? vic ? 16fev11 23. random number generator at90scr100/116/132 23. random number generator 23.1 features ? automatic generation of 8-bits random number ? private oscillator source used for unpredictable random generation 23.2 rng definition the random number generator of the at90scr100/116/132 uses a specific oscillator source controlled by the rngcr.rosce bit. this oscillator adapt is used to activate a hardware process. this hardware process can be seeded through the lfsr3 to lfsr0 registers. the result of the hardware post-processing can be read from the rdwdr register. lfsr3 to lfsr0 registers must be changed while the oscillator source is stopped (rngcr.rosce bit is cleared). when rngcr.rosce bit is cleared, the oscillator source is stopped (as well as the shift regis- ter and the hardware post processing). when rngcr.rosce bit is set, the oscillator is activated and the configuration of the shift reg- ister and of the hardware post-processing depends on the lfsr registers and previous hardware iterations. note note after chip start-up, some oscillator cycles will be performed in order to initialise to a different random value after each chip power-up. oscillator hardware postprocessing lfsr0 to lfsr3 rdwdr
at90scr100/116/132 344 tpr0327b ? vic ? 16fev11 23.3 random number generator registers 23.3.1 rngcr - random number generator control register ? bit 7..1 : reserved for future use these bits are reserved for future use. ? bit 0 - rosce: random oscillator enable set this bit to enable the oscillator source and to start the random number generation. clear this bit to stop the execution of the random number generator. the value of the lfsrn and rdwdr registers will retain the value of the last oscillator step. 23.3.2 lfsr0 to lfsr3 - initialization registers ? bit 31..0 - lfsdxx: current lfsr generator value these registers can be loaded, with an initial seed value for the hardware process, if the pmcr.rosce bit is cleared. the values of lfsrx registers are changed between two 8/16-bit risc cpu clock cycles. bit 76543 2 10 $000095 ----- - -roscerngcr read/write r r r r r r r r/w initial value 0 0 0 0 0 0 0 0 0x00 bit 76543 2 10 $000094 lfsd [31..24] lfsr3 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial valuexxxxx x xx bit 76543 2 10 $000093 lfsd [23..16] lfsr2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial valuexxxxx x xx bit 76543 2 10 $000092 lfsd [15..8] lfsr1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial valuexxxxx x xx bit 76543 2 10 $000091 lfsd [7..0] lfsr0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial valuexxxxx x xx
345 tpr0327b ? vic ? 16fev11 23. random number generator at90scr100/116/132 23.3.3 rdwdr - random word data register ? bit 7..0 - rddx: random word generator result value returns the post-processed random value. at each 8/16-bit risc cpu clock this register value is changed with a value derived from the hardware process, seeded by the lfsr0 to lfsr3 registers. bit 76543210 $000090 rdd [7..0] rdwdr read/writerrrrrrrr initial valuexxxxxxxx
at90scr100/116/132 346 tpr0327b ? vic ? 16fev11
347 tpr0327b ? vic ? 16fev11 24. keyboard interface at90scr100/116/132 24. keyboard interface 24.1 features ? allows connection of a 8x8 matrix keyboard ? based on 8 inputs pins and 8 outputs specific pins ? supports slow edge pads to avoid abusive emc generation (on outputs pads only) ? specific keyboard pins only available in full pin count package. see ?pin list configuration? on page 15. ? allows chip wake-up on key pressed event 24.2 general description 24.2.1 overview the keyboard interfaces with the 8/16-bit risc cpu core through 3 registers: kbls, the key- board level selection register ( page 350 ), kbe, the keyboard inte rrupt enable register ( page 349 ), and kbf, the keyboard flag register ( page 348 ). 24.2.2 interrupt the keyboard inputs are considered as 8 independant interrupt sources sharing the same inter- rupt vector. an interrupt enable bit allows global enable or disable of the keyboard interrupt (see figure 24-1 ). as detailed in figure 24-2 each keyboard input can detect a programmable level according to kbls.x bit value. level detection is then reported in interrupt flags kbfr.x that can be masked by software using kber.x bits. the kbfr.x flags are set by hardware when an active level is on input pax. the kbfr register is reset by writing any data inside the kbfr. figure 24-1. keyboard interface block diagram note note you can choose to create a keyboard interface only by using pin change man- agement.this module?s purpose is to ease the creation of little pinpads. input circuitry input circuitry input circuitry input circuitry input circuitry kbin 0 kbin 1 kbin 2 kbin 3 kbin 4 pa0: pa1: pa2: pa3: pa4: input circuitry kbin 5 pa5: input circuitry kbin 6 pa6: input circuitry kbin 7 pa7: global it bit keyboard it keyboard interface interrupt request
at90scr100/116/132 348 tpr0327b ? vic ? 16fev11 figure 24-2. keyboard input circuitry 24.2.3 power reduction mode keyboard inputs allow wake up from power-down, power-save, standby, extended standbay modes ?active clock domains and wake-up sources in the different sleep modes.? on page 53 . 24.3 keyboard register description 24.3.1 kbfr - keyboard flag register ? bit 7- kbf7: keyboard flag for kbin7 pin set by hardware when the pin function kbin7 (pa7) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe7 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register ? bit 6 - kbf6: keyboard flag for kbin6 pin set by hardware when the pin function kbin6 (pa6) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe6 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register ? bit 5 - kbf5: keyboard flag for kbin5 pin set by hardware when the pin function kbin5 (pa5) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe5 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register ? bit 4 - kbf4: keyboard flag for kbin4 pin set by hardware when the pin function kbin4 (pa4) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe4 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register ? bit 3 - kbf3 : keyboard flag for kbin3 pin set by hardware when the pin function kbin3 (pa3) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe3 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register kbls.x kbin x kbf.x kbe.x 0 1 bit 76543 2 10 $008f kbf7 kbf6 kbf5 kbf4 kbf 3 kbf2 kbf1 kbf0 kbfr 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 0x00
349 tpr0327b ? vic ? 16fev11 24. keyboard interface at90scr100/116/132 ? bit 2 - kbf2 : keyboard flag for kbin2 pin set by hardware when the pin function kbin2 (pa2) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe2 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register ? bit 1 - kbf1: keyboard flag for kbin1 pin set by hardware when the pin function kbin1 (pa1) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe1 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register ? bit 0 - kbf0 : keyboard flag for kbin0 pin set by hardware when the pin function kbin0 (pa0) detects a programmed level. it generates a keyboard interrupt request if the kber.kbe0 bit is set. writing a ?0? or a ?1? into this bit will erase all the bits (including this one) of the kbfr register 24.3.2 kber - keyboard enable register ? bit 7- kbe7 : keyboard kbin7 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf7 to generate an interrupt request. ? bit 6- kbe6 : keyboard kbin6 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf6 to generate an interrupt request. ? bit 5- kbe5 : keyboard kbin5 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf5 to generate an interrupt request. ? bit 4 - kbe4 : keyboard kbin4 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf4 to generate an interrupt request. ? bit 3 - kbe3 : keyboard kbin3 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf3 to generate an interrupt request. ? bit 2 - kbe2 : keyboard kbin2 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf2 to generate an interrupt request. bit 76543 2 10 $008e kbe7 kbe6 kbe5 kbe4 kbe3 kbe2 kbe1 kbe0 kber 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 0x00
at90scr100/116/132 350 tpr0327b ? vic ? 16fev11 ? bit 1 - kbe1 : keyboard kbin1 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf1 to generate an interrupt request. ? bit 0 - kbe0 : keyboard kbin0 enable bit cleared to enable standard i/o pin. set to enable kbfr.kbf0 to generate an interrupt request. 24.3.3 kblsr - keyboard level selection register ? bit 7- kbls7 : keyboard kbin7 level selection bit cleared to enable low level detection on kbin7. set to enable a high level detection on kbin7. ? bit 6- kbls6 : keyboard kbin6 level selection bit cleared to enable low level detection on kbin6. set to enable a high level detection on kbin6. ? bit 5 - kbls5 : keyboard kbin5 level selection bit cleared to enable low level detection on kbin5. set to enable a high level detection on kbin5. ? bit 4 - kbls4 : keyboard kbin4 level selection bit cleared to enable low level detection on kbin4. set to enable a high level detection on kbin4. ? bit 3 - kbls3 : keyboard kbin3 level selection bit cleared to enable low level detection on kbin3. set to enable a high level detection on kbin3. ? bit 2 - kbls2 : keyboard kbin2 level selection bit cleared to enable low level detection on kbin2. set to enable a high level detection on kbin2. ? bit 1 - kbls4 : keyboard kbin1 level selection bit cleared to enable low level detection on kbin1. set to enable a high level detection on kbin1. ? bit 0 - kbls0 : keyboard kbin0 level selection bit cleared to enable low level detection on kbin0. bit 76543 2 10 $008d kbls7 kbls6 kbls5 kbls4 kbls3 kbls2 kbls1 kbls0 kblsr 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 0x00
351 tpr0327b ? vic ? 16fev11 24. keyboard interface at90scr100/116/132 set to enable a high level detection on kbin0.
at90scr100/116/132 352 tpr0327b ? vic ? 16fev11
353 tpr0327b ? vic ? 16fev11 25. aes 128/256 engine at90scr100/116/132 25. aes 128/256 engine to support all the security needs and requirements of embedded systems, the at90scr100/116/132 features a hardware aes engine. it provides an efficient and easy way to perform standard cryptographic calculus. 25.1 features ? 128 and 256 bits key length ? encryption and decryption algorithm ? supports ecb, cbc, and mac algorithms ? specific encryption/decryption key generation for optimized revet algorithm ? auto-incremented pointer register on data write for fast data loading ? interrupt generation on calculus completion 25.2 overview the aes module of the at90scr100/116/132 includes an internal memory, dedicated to aes management. these registers are not directly accessible from the 8/16-bit risc cpu core, and the user must use a specific interface to write both key and data. the aes module can only manage one data block of 128 bits at a time. the figure below shows how to access the internal memory of the aes block: figure 25-1. aes block interface aes key register aes engine aes control system aes block aes data register internal memory 0x00 0x00 0x31 0x15 aesdr aesaddr aesacr address decoder aesacr.kd aesacr.kd=0 aesacr.kd=1 aes interrupt signal
at90scr100/116/132 354 tpr0327b ? vic ? 16fev11 25.2.1 memory organization there are 2 address areas: key and data. internal registers can be observed or modified via the aesaddr and aesdr registers. below is a way to organize the memory according to an example: figure 25-2. example of memory organization assembly code is available in section ?example. code sample? on page 357 . caution ! all bytes must be reverted in the aes data and key memory. this means that the data must be oriented first bits of the aes key in first. caution ! as memory is reversed, the first bits of the aes 128key will start at address #16 and the last bits of aes128 key will be at address #31 caution ! the result is also inverted in data internal memory (first bits of the key in first). 00010203050607080a0b0c0d0f101112 aes128 key: 506812a45f08c889b97f5980038b8359 data to cipher: ciphered message: d8f532538289ef7d06b506a4fd5be9c9 aes_key 12 11 10 0f 0d 0c 0b 0a 08 07 06 05 03 02 01 00 #0 #15 #16 #31 aes_data 59 83 8b 03 80 59 7f b9 89 c8 08 5f a4 12 68 50 #00 #15 aes_result this is what can be read in the data register after aes run of aes128 encryption c9 e9 5b fd a4 06 b5 06 7d ef 89 82 53 32 f5 d8 #00 #15
355 tpr0327b ? vic ? 16fev11 25. aes 128/256 engine at90scr100/116/132 25.3 aes registers description 25.3.1 aescr - aes control register ? bit 7 - aesie : aes interrupt enable set (one) this bit to enable interrupt generation when aes operation is ended. clear (zero) this bit to disable aes interrupt generation. ? bit 6 - aesif : aes interrupt flag this bit is set by hardware on aes operation completion. if aesie and sreg.i are set, an inter- rupt is automatically generated. this bit must be cleared by software. ? bit 5 - autokey : encrypt/decrypt automatic key generation mode this bit is set and cleared by software. if this bit is set, when aesgo is set, a decryption (encryption) key is automatically generated from the encryption (decryption) key and will be used in the decryption (encryption) operation. this key is available in the key internal register and can be read. if this bit is cleared, then aesgo performs a standard operation, using the key in its buffer. ? bit 4 - keygn : key generation mode this bit is set and cleared by software. this bit allows a decryption key to be generated from an encryption key without processing aes data (which means that aes data registers won?t change). when in this mode, a decryption key will be calculated from an encryption key if the encrypt bit is set and an encryption key will be calculated from a decryption key if the encrypt bit is cleared. if this bit is set, aes key calculation will be perform when setting aesgo bit. if this bit is cleared, aesgo bit will perform a standard operation, processing aes data. ? bit 3 - ks : key selection bit this bit is set and cleared by software. set this bit to activate aes256 mode, using 256 bits key. clear this bit to activate aes128 mode, using first 128 bits of the aes key (key[0..15]). the last bits (key[16..31]) are unused. ? bit 2 - reserved bit this bit is reserved for future use. ? bit 1 - encrypt : encryption/decryption bit bit 765432 1 0 $0078 aesie aesif autokey keygn ks - encrypt aesgo aescr read/write r/w r/w r/w r/w r/w r r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
at90scr100/116/132 356 tpr0327b ? vic ? 16fev11 this bit is set and cleared by software. set this bit to perform aes encryption when setting aesgo. clear this bit to perform aes decryption when setting aesgo. ? bit 0 - aesgo : aes run bit this bit is set by software and cleared by hardware. set this bit to run aes operation specified by the other register settings. this bit is cleared by hardware when the aes operation is comp lete. if this bit is equal to one, then the aes block is running and busy. 25.3.2 aesacr - aes access control register ? bit 7..4 - reserved bits these bits are reserved for future use. ? bit 3 - xor : xor mode this bit is set and cleared by software. this bit has no influence if the kd bit is set. when this bit is cleared, writing new data in aesdr will copy the data in aes data memory, in accordance with aesaddr register. when this bit is set and new data is written into the aesdr, the data to the aes data memory, according to aesaddr register, will be ?xored? with the new data. this is useful when perform- ing a cbc algorithm, or mac generation. ? bit 2 - maninc : manual increment bit this bit is a write-only bit and always reads as ?0?. this bit can only be set. setting this bit will increment the aesaddr register by one. ? bit 1 - autoinc : automatic increment bit this bit is set and cleared by software. if this bit is set, writing new data in th aesdr register will automatically increment the aesaddr register by one, after the new data is loaded. the mechanism of automatic aesdr changes are active, which means that the aesdr contents will be updated with the data pointed by the new aesaddr register value. if this bit is cleared, the automatic increment is disabled. ? bit 0 - kd : key/data bit bit 7 6 5 4 3 2 1 0 $0079 ----xormanincautoinckdaesacr read/writerrrrr/wwr/wr/w initial value 0 0 0 0 0 0 1 0 0x02 note note when performing a write operation to the ae sacr register, with this bit set, it is not possible to change the state of the ot her register bits. this prevents the user accidentally changing the functional op eration of the aes during a manual incre- ment operation.
357 tpr0327b ? vic ? 16fev11 25. aes 128/256 engine at90scr100/116/132 this bit is set and cleared by software. when this bit is cleared, aesaddr register points to key aes registers. when this bit is set, aesaddr register points to data aes registers. 25.3.3 aesaddr - aes address register this register permits to target a specific byte inside aes internal memory. according to aesacr.kd value, the aesaddr targets key of data internal registers. when writing this register, the aesdr data register will be updated to the newly data or key byte pointed. this register can be automatically increment, if aesacr.autoinc bit is set, when writing new data in aesdr. this will update aesdr after write operation, to the newly pointed byte. 25.3.4 aesdr - aes data register this register permits to observe the internal key and data registers of the aes block. when aesaddr register is modified, this regist er is updated to the newly pointed address. when writing aesdr regi ster, the data targeted by aesacr.kd and aesaddr will be auto- matically updated, according to aesacr.xor bit. 25.4 example. code sample below is code examples of how to initialize aes block to perform aes cbc. ;- this routine performs a aes128 bit encryption ;-registers used: ; storing and restoring of registers is not included in the routine ; register usage can be optimized at the expense of code size ;-when jumping into these procedures, z targets the key to use and ;y the data to encrypt. x targets to the storage of the encrypted ;data ;-it is assumed that interruptions are disabled vaes128_encrypt: ; loading key ldi r16, (1< at90scr100/116/132 358 tpr0327b ? vic ? 16fev11 ldi r16, 0x10 sts aesaddr, r16 call keydata_load ; loading data ldi r16, (1< 359 tpr0327b ? vic ? 16fev11 25. aes 128/256 engine at90scr100/116/132 ret ;---------------------------------------------------------- keydata_load: ldi r16, 16 ; update z register for reverted copy adiw zl, 16 keydata_load_loop: ld r17, -z sts aesdr, r17 dec r16 brne keydata_load_loop ret
at90scr100/116/132 360 tpr0327b ? vic ? 16fev11
361 tpr0327b ? vic ? 16fev11 26. jtag interface and on-chip debug system at90scr100/116/132 26. jtag interface and on-chip debug system 26.1 features ? jtag (ieee std. 1149.1 compliant) interface ? boundary-scan capabilities according to the ieee std. 1149.1 (jtag) standard ? debugger access to: ? all internal peripheral units ? internal ram ? the internal register file ? program counter ? eeprom and flash memories ? extensive on-chip debug support for break conditions, including ? 8/16-bit risc cpu break instruction ? break on change of program memory flow ? single step break ? program memory break points on single address or address range ? data memory break points on single address or address range ? programming of flash, eeprom, fuses, and lock bits through the jtag interface ? on-chip debugging supported by 8/16-bit risc cpu studio ? 26.2 overview the 8/16-bit risc cpu ieee std. 1149.1 compliant jtag interface can be used for ? testing pcbs by using the jtag boundary-scan capability ? programming the non-volatile memories, fuses and lock bits ? on-chip debugging a brief description is given in the following sections. detailed descriptions for programming via the jtag interface, and using the boundary-scan chain can be found in the sections ?program- ming via the jtag interface? on page 399 and ?ieee 1149.1 (jtag) boundary-scan? on page 367 , respectively. the on-chip debug support is considered being private jtag instructions, and distributed within inside secure and to selected third party vendors only. figure 26-1 shows a block diagram of the jtag interface and the on-chip debug system. the tap controller is a state machine controlled by the tck and tms signals. the tap controller selects either the jtag instruction register or one of several data registers as the scan chain (shift register) between the tdi ? input and tdo ? output. the instruction register holds jtag instructions controlling the behavior of a data register. the id-register, bypass register, and the boundary-scan chain are the data registers used for board-level testing. the jtag programming interface (actually consisting of several physical and virtual data registers) is used for serial programming via the jtag interface. the internal scan chain and break point scan chain are used for on-chip debugging only. 26.3 tap ? test access port the jtag interface is accessed through four of the 8/16-bit risc cpu?s pins. in jtag terminol- ogy, these pins constitute the test access port ? tap. these pins are: ? tms _ jtgtms: test mode select. this pin is used for navigating through the tap-controller state machine. ? tck _ jtgtck: test clock. jtag operation is synchronous to tck.
at90scr100/116/132 362 tpr0327b ? vic ? 16fev11 ? tdi _ jtgtdi: test data in. serial input data to be shifted in to the instruction register or data register (scan chains). ? tdo _ jtgtdo: test data out. serial output data from instruction register or data register. the ieee std. 1149.1 also specifies an optional tap signal; trst ? test reset ? which is not provided. when the jtagen fuse is unprogrammed, these four tap pins are normal port pins, and the tap controller is in reset. when programmed, the input tap signals are internally pulled high and the jtag is enabled for boundary-scan and programming. the device is shipped with this fuse programmed. for the on-chip debug system, in addition to the jtag interface pins, the reset pin is moni- tored by the debugger to be able to detect external reset sources. the debugger can also pull the reset pin low to reset the whole system, assuming only open collectors on the reset line are used in the application. figure 26-1. block diagram tap controller tdi tdo tck tms flash memory 8/16-bit risc cpu digital peripheral units jtag / 8/16-bit risc cpu core communication interface breakpoint unit flow control unit ocd status and control internal scan chain m u x instruction register id register bypass register jtag programming interface pc instruction address data breakpoint scan chain address decoder analog peripherial units i/o port 0 i/o port n boundary scan chain analog inputs control & clock lines device boundary
363 tpr0327b ? vic ? 16fev11 26. jtag interface and on-chip debug system at90scr100/116/132 figure 26-2. tap controller state diagram 26.4 tap controller the tap controller is a 16-state finite state machine that controls the operation of the boundary- scan circuitry, jtag programmi ng circuitry, or on-chip debug system. the state transitions depicted in figure 26-2 depend on the signal present on tms (shown adjacent to each state transition) at the time of the rising edge at tck. the initial state after a power-on reset is test- logic-reset. as a definition in this document, the lsb is shifted in and out first for all shift registers. assuming run-test/idle is the present state, a typical scenario for using the jtag interface is: ? at the tms input, apply the sequence 1, 1, 0, 0 at the rising edges of tck to enter the shift instruction register ? shift-ir state. while in this state, shift the four bits of the jtag instructions into the jtag instruction register from the tdi input at the rising edge of tck. the tms input must be held low during input of the 3 lsbs in order to remain in the shift-ir state. the msb of the instruction is shifted in when this state is left by setting tms high. while the instruction is shifted in from the tdi pin, the captured ir-state 0x01 is shifted out on the tdo pin. the jtag instruction selects a particular data register as path between tdi and tdo and controls the circuitry surrounding the selected data register. test-logic-reset run-test/idle shift-dr exit1-dr pause-dr exit2-dr update-dr select-ir scan capture-ir shift-ir exit1-ir pause-ir exit2-ir update-ir select-dr scan capture-dr 0 1 0 11 1 00 00 11 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1
at90scr100/116/132 364 tpr0327b ? vic ? 16fev11 ? apply the tms sequence 1, 1, 0 to re-enter the run-test/idle state. the instruction is latched onto the parallel output from the shift register path in the update-ir state. the exit-ir, pause-ir, and exit2-ir states are only used for navigating the state machine. ? at the tms input, apply the sequence 1, 0, 0 at the rising edges of tck to enter the shift data register ? shift-dr state. while in this state, upload the selected data register (selected by the present jtag instruction in the jtag instruction register) from the tdi input at the rising edge of tck. in order to remain in the shift-dr state, the tms input must be held low during input of all bits except the msb. the msb of the data is shifted in when this state is left by setting tms high. while the data register is shifted in from the tdi pin, the parallel inputs to the data register captured in the capture-dr state is shifted out on the tdo pin. ? apply the tms sequence 1, 1, 0 to re-enter the run-test/idle state. if the selected data register has a latched parallel-output, the latching takes place in the update-dr state. the exit-dr, pause-dr, and exit2-dr states are only used for navigating the state machine. as shown in the state diagram, the run-test/idle state need not be entered between selecting jtag instruction and using data registers, and some jtag instructions may select certain functions to be performed in the run-test/idle, making it unsuitable as an idle state. for detailed information on the jtag specification, refer to the literature listed in ?bibliography? on page 366 . 26.5 using the boundary-scan chain a complete description of the boundary-scan capabilities are given in the section ?ieee 1149.1 (jtag) boundary-scan? on page 367 . 26.6 using the on-chip debug system as shown in figure 26-1 , the hardware support for on-chip debugging consists mainly of ? a scan chain on the interface between the internal 8/16-bit risc cpu and the internal peripheral units. ? break point unit. ? communication interface between the cpu and jtag system. all read or modify/write operations needed for implementing the debugger are done by applying 8/16-bit risc cpu instructions via the internal 8/16-bit risc cpu scan chain. the cpu sends the result to an i/o memory mapped location which is part of the communication interface between the cpu and the jtag system. the break point unit implements break on change of program flow, single step break, two program memory break points, and two combined break points. together, the four break points can be configured as either: ? 4 single program memory break points. ? 3 single program memory break point + 1 single data memory break point. ? 2 single program memory break points + 2 single data memory break points. note note independent of the initial state of the tap controller, the test-logic-reset state can always be entered by holding tms high for five tck clock periods.
365 tpr0327b ? vic ? 16fev11 26. jtag interface and on-chip debug system at90scr100/116/132 ? 2 single program memory break points + 1 program memory break point with mask (?range break point?). ? 2 single program memory break points + 1 data memory break point with mask (?range break point?). a debugger, like the 8/16-bit risc cpu studio, may however use one or more of these resources for its internal purpose, leaving less flexibility to the end-user. a list of the on-chip debug specific jtag instructions is given in ?on-chip debug specific jtag instructions? on page 365 . the jtagen fuse must be programmed to enable the jtag test access port. in addition, the ocden fuse must be programmed and no lock bits must be set for the on-chip debug system to work. as a security feature, the on-chip debug system is disabled when either of the lb1 or lb2 lock bits are set. otherwise, the on-chip debug system would have provided a back-door into a secured device. the 8/16-bit risc cpu studio enables the user to fully control execution of programs on a 8/16- bit risc cpudevice with on-chip debug capabilit y, 8/16-bit risc cpu in-circuit emulator, or the built-in 8/16-bit risc cpu instruction set simulator. 8/16-bit risc cpu studio ? supports source level execution of assembly programs assembled with inside secure corporation?s 8/16- bit risc cpu assembler and c programs compiled with third party vendors? compilers. for a full description of the 8/16-bit risc cpu studio, please refer to the 8/16-bit risc cpu studio user guide. only highlights are presented in this document. you can also find informa- tion on the inside secure internet website. all necessary execution commands are available in 8/16-bit risc cpu studio, both on source level and on disassembly level. the user can execute the program, single step through the code either by tracing into or step ping over functions, step out of functions, place the cursor on a statement and execute until the statement is reached, stop the execution, and reset the execu- tion target. in addition, the user can have an unlimited number of code break points (using the break instruction) and up to two data memory break points, alternatively combined as a mask (range) break point. 26.7 on-chip debug specific jtag instructions the on-chip debug support is considered being private jtag instructions, and distributed within inside secure and to selected third party vendors only. instruction opcodes are listed for reference. 26.7.1 private0; 0x8 private jtag instruction for accessing on-chip debug system. 26.7.2 private1; 0x9 private jtag instruction for accessing on-chip debug system. 26.7.3 private2; 0xa private jtag instruction for accessing on-chip debug system. 26.7.4 private3; 0xb private jtag instruction for accessing on-chip debug system.
at90scr100/116/132 366 tpr0327b ? vic ? 16fev11 26.8 on-chip debug related register in i/o memory 26.8.1 ocdr ? on-chip debug register the ocdr register provides a communication channel from the running program in the micro- controller to the debugger. the cpu can transfer a byte to the debugger by writing to this location. at the same time, an internal flag; i/o debug register dirty ? idrd ? is set to indicate to the debugger that the register has been wri tten. when the cpu reads the ocdr register the 7 lsb will be from the ocdr register, while th e msb is the idrd bit. the debugger clears the idrd bit when it has read the information. in some 8/16-bit risc cpu devices, this register is shared with a standard i/o location. in this case, the ocdr register can only be accessed if the ocden fuse is programmed, and the debugger enables access to the ocdr register. in all other cases, the standard i/o location is accessed. refer to the debugger documentation for further information on how to use this register. 26.9 using the jtag programming capabilities programming of 8/16-bit risc cpu parts via jtag is performed via the 4-pin jtag port, tck, tms, tdi, and tdo. these are the only pins that need to be controlled/observed to perform jtag programming (in addition to power pins). it is not required to apply 12v externally. the jtagen fuse must be programmed and the jtd bit in the mcucr register must be cleared to enable the jtag test access port. see ?mcucr ? mcu control register? on page 370. the jtag programming capability supports: ? flash programming and verifying. ? eeprom programming and verifying. ? fuse programming and verifying. ? lock bit programming and verifying. if the lock bits lb1 or lb2 are programmed, the ocden fuse cannot be programmed unless first doing a chip erase. this is a security fe ature that ensures no back-door exists for reading out the content of a secured device. the details on programming through the jtag interface and programming specific jtag instructions are given in the section ?programming via the jtag interface? on page 399 . 26.10 bibliography for more information about general boundary-scan, the following literature can be consulted: ? ieee: ieee std. 1149.1-1990. ieee standard test access port and boundary-scan architecture, ieee, 1993. ? colin maunder: the board designers guide to testable logic circuits, addison-wesley, 1992. bit 76543 2 10 0x31 (0x51) d7/idrd d6 d5 d4 d3 d2 d1 d0 ocdr 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 0x00
367 tpr0327b ? vic ? 16fev11 27. ieee 1149.1 (jtag) boundary-scan at90scr100/116/132 27. ieee 1149.1 (jtag) boundary-scan 27.1 features ? jtag (ieee std. 1149.1 compliant) interface ? boundary-scan capabilities according to the jtag standard ? full scan of all port functions as well as analog circuitry having off-chip connections ? supports the optional idcode instruction ? additional public avr_reset instruction to reset the 8/16-bit risc cpu 27.2 system overview the boundary-scan chain has the capability of driving and observing the logic levels on the digi- tal i/o pins, as well as the boundary between digital and analog logic for analog circuitry having off-chip connections. at system level, all ics having jtag capabilities are connected serially by the tdi/tdo signals to form a long shift register. an external controller sets up the devices to drive values on their output pins, and observe the input values received from other devices. the controller compares the received data with the expected result. in this way, boundary-scan pro- vides a mechanism to test interconnections and integrity of components on printed circuits boards by using the four tap signals only. the four ieee 1149.1 defined mandatory jtag instructions idcode, bypass, sample/pre- load, and extest, as well as the 8/16-bit risc cpu specific public jtag instruction avr_reset can be used to test the printed circuit board. initial scanning of the data register path will show the id-code of the device, as idcode is the default jtag instruction. it is advised to have the 8/16-bit risc cpu device in reset during test mode. if not reset, inputs to the device may be determined by the scan operations, and the internal software may remain in an undetermined state when exiting the test mode. entering reset, the outputs of any port pin will instantly enter in high impedance state, making the highz instruction redundant. if needed, the bypass instruction can be issued to make the shortest possible scan chain through the device. the device can be set in the reset state either by pulling the external reset pin low, or issuing the avr_reset instruction with appropriate setting of the reset data register. the extest instruction is used to sample external pins and load output pins with data. the data from the output latch will be driven out on the pins as soon as the extest instruction is loaded into the jtag ir-register. therefore, the sample/preload should also be used to set initial values to the scan ring, to avoid damaging the board when issuing the extest instruction for the first time. sample/preload can also be used to take a snapshot of the external pins during normal operation of the part. the jtagen fuse must be programmed and the jtd bit in the i/o register mcucr must be cleared to enable the jtag test access port. when using the jtag interface for boundary-scan, using a jtag tck clock frequency higher than the internal chip frequency is possible. the chip clock is not required to run. 27.3 data registers the data registers relevant for boundary-scan operations are: ? bypass register ? device identification register ? reset register ? boundary-scan chain
at90scr100/116/132 368 tpr0327b ? vic ? 16fev11 27.3.1 bypass register the bypass register consists of a single shif t register stage. when the bypass register is selected as path between tdi and tdo, the register is reset to 0 when leaving the capture-dr controller state. the bypass register can be used to shorten the scan chain on a system when the other devices are to be tested. 27.3.2 device identification register figure 27-1 shows the structure of the device identification register. figure 27-1. the format of the device identification register version version is a 4-bit number identifying the revision of the component. the jtag version number follows the revision of the device. revision a is 0x0, revision b is 0x1 and so on. part number the part number is a 16-bit code identifying the component. the jtag part number for at90scr100/116/132 is listed in table 29-6 on page 394 . manufacturer id the manufacturer id is a 11-bit code identifyin g the manufacturer. the jtag manufacturer id for inside secure is listed in table 29-6 on page 394 . 27.3.3 reset register the reset register is a test data register used to reset the part. since the 8/16-bit risc cpu tri-states port pins when reset, the reset register can also replace the function of the unimple- mented optional jtag instruction highz. a high value in the reset register corresponds to pulling the external reset low. the part is reset as long as there is a high value present in the reset register. depending on the fuse set- tings for the clock options, the part will remain reset for a reset time-out period (refer to table 7- 3 on page 45 ) after having released the reset register. the output from this data register is not latched, so the reset will take place immediately, as shown in figure 27-2 . msb lsb bit 31 2827 1211 1 0 device id version part number manufacturer id 1 4 bits 16 bits 11 bits 1-bit
369 tpr0327b ? vic ? 16fev11 27. ieee 1149.1 (jtag) boundary-scan at90scr100/116/132 figure 27-2. reset register 27.3.4 boundary-scan chain the boundary-scan chain has the capability of driving and observing the logic levels on the dig- ital i/o pins, as well as the boundary between digital and analog logic for analog circuitry having off-chip connections. see ?boundary-scan chain? on page 371 for a complete description. 27.4 boundary-scan specific jtag instructions the instruction register is 4-bit wide, support ing up to 16 instructions. listed below are the jtag instructions useful for boundary-scan operation. note that the optional highz instruction is not implemented, but all outputs with tri-state capability can be set in high-impedant state by using the avr_reset instruction, since the initial state for all port pins is tri-state. as a definition in this datasheet, the lsb is shifted in and out first for all shift registers. the opcode for each instruction is shown behind the instruction name in hex format. the text describes which data register is selected as path between tdi and tdo for each instruction. 27.4.1 extest; 0x0 mandatory jtag instruction for selecting the boundary-scan chain as data register for testing circuitry external to the 8/16-bit risc cpu package. for port-pins, pull-up disable, output con- trol, output data, and input data are all accessible in the scan chain. for analog circuits having off-chip connections, the interface between the analog and the digital logic is in the scan chain. the contents of the latched outputs of the boundary-scan chain is driven out as soon as the jtag ir-register is loaded with the extest instruction. the active states are: ? capture-dr: data on the external pins are sampled into the boundary-scan chain. ? shift-dr: the internal scan chain is shifted by the tck input. ? update-dr: data from the scan chain is applied to output pins. 27.4.2 idcode; 0x1 optional jtag instruction selecting the 32 bit id-register as data register. the id-register consists of a version number, a device number and the manufacturer code chosen by jedec. this is the default instruction after power-up. dq from tdi clockdr avr_reset to tdo from other internal and external reset sources internal reset
at90scr100/116/132 370 tpr0327b ? vic ? 16fev11 the active states are: ? capture-dr: data in the idcode register is sampled into the boundary-scan chain. ? shift-dr: the idcode scan chain is shifted by the tck input. 27.4.3 sample_preload; 0x2 mandatory jtag instruction for pre-loading the output latches and taking a snap-shot of the input/output pins without affecting the system operation. however, the output latches are not connected to the pins. the boundary-scan chain is selected as data register. the active states are: ? capture-dr: data on the external pins are sampled into the boundary-scan chain. ? shift-dr: the boundary-scan chain is shifted by the tck input. ? update-dr: data from the boundary-scan chain is applied to the output latches. however, the output latches are not connected to the pins. 27.4.4 avr_reset; 0xc the 8/16-bit risc cpu specific public jtag instruction for forcing the 8/16-bit risc cpu device into the reset mode or releasing the jtag reset source. the tap controller is not reset by this instruction. the one bit reset register is selected as data register. note that the reset will be active as long as there is a logic ?one? in the reset chain. the output from this chain is not latched. the active states are: ? shift-dr: the reset register is shifted by the tck input. 27.4.5 bypass; 0xf mandatory jtag instruction selecting the bypass register for data register. the active states are: ? capture-dr: loads a logic ?0? into the bypass register. ? shift-dr: the bypass register cell between tdi and tdo is shifted. 27.5 boundary-scan related register in i/o memory 27.5.1 mcucr ? mcu control register the mcu control register contains control bits for general mcu functions. ? bit 7 ? jtd: jtag interface disable when this bit is zero, the jtag interface is enabled if the jtagen fuse is programmed. if this bit is one, the jtag interface is disabled. in order to avoid unintentional disabling or enabling of the jtag interface, a timed sequence must be followed when changing this bit: the application software must write this bit to the desired value twice within four cycles to change its value. note that this bit must not be altered when using the on-chip debug system. bit 76543 2 10 0x35 (0x55) jtd - - pud - - ivsel ivce mcucr read/write r/w r r r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 0x00
371 tpr0327b ? vic ? 16fev11 27. ieee 1149.1 (jtag) boundary-scan at90scr100/116/132 ? others bits: other bits are defined in other sections of the datasheet, but do not refer to the boundary scan management. 27.5.2 mcusr ? mcu status register the mcu status register provides information on which reset source caused an mcu reset. ? bit 4 ? jtrf: jtag reset flag this bit is set if a reset is being caused by a logic one in the jtag reset register selected by the jtag instruction avr_reset. this bit is rese t by a power-on reset, or by writing a logic zero to the flag. ? others bits: other bits are defined in other sections of the datasheet, but do not refer to the boundary scan management. 27.6 boundary-scan chain the boundary-scan chain has the capability of driving and observing the logic levels on the digi- tal i/o pins, as well as the boundary between digital and analog logic for analog circuitry having off-chip connection. 27.6.1 scanning the digital port pins figure 27-3 shows the boundary-scan cell for a bi-directional port pin. the pull-up function is disabled during boundary-scan when the jtag ir contains extest or sample_preload. the cell consists of a bi-directional pin cell t hat combines the three signals output control - ocxn, output data - odxn, and input data - idxn, into only a two-stage shift register. the port and pin indexes are not used in the following description the boundary-scan logic is not included in the figures in the datasheet. figure 27-4 shows a simple digital port pin as described in the section ?i/o ports? on page 83 . the boundary-scan details from figure 27-3 replaces the dashed box in figure 27-4 . when no alternate port function is present, the input data - id - corresponds to the pinxn regis- ter value (but id has no synchronizer), output data corresponds to the port register, output control corresponds to the data direction - dd register, and the pull-up enable - puexn - cor- responds to logic expression pud ddxn portxn. digital alternate port functions are connected outside the dotted box in figure 27-4 to make the scan chain read the actual pin value. for analog function, there is a direct connection from the external pin to the analog circuit. there is no scan chain on the interface between the digital and the analog circuitry, but some digital control signal to analog circuitry are turned off to avoid driv- ing contention on the pads. when jtag ir contains extest or sample_preload the clock is not sent out on the port pins even if the ckout fuse is programmed. even though the clock is output when the jtag ir contains sample_preload, the clock is not sampled by the boundary scan. bit 76543 2 10 0x34 (0x54) - - -jtrf wdrf borf extrf porf mcusr read/write r r r r/w r/w r/w r/w r/w initial value 0 0 0 x x x x x
at90scr100/116/132 372 tpr0327b ? vic ? 16fev11 figure 27-3. boundary-scan cell for bi-directional port pin with pull-up function. dq dq g 0 1 0 1 dq dq g 0 1 0 1 0 1 port pin (pxn) vcc extest to next cell shiftdr output control (oc) output data (od) input data (id) from last cell updatedr clockdr ff1 ld1 ld0 ff0 0 1 ull-up enable (pue)
373 tpr0327b ? vic ? 16fev11 27. ieee 1149.1 (jtag) boundary-scan at90scr100/116/132 figure 27-4. general port pin schematic diagram 27.6.2 scanning the reset pin the reset pin accepts 5v active low logic for standard reset operation. an observe-only cell as shown in figure 27-5 is inserted for the 5v reset signal. figure 27-5. observe-only cell clk rpx rrx wrx rdx wdx pud synchronizer wdx: write ddrx wrx: write portx rrx: read portx register rpx: read portx pin pud: pullup disable clk : i/o clock rdx: read ddrx d l q q reset reset q q d q q d clr portxn q q d clr ddxn pinxn data bus sleep sleep: sleep control pxn i/o i/o see boundary-scan description for details! puexn ocxn odxn idxn puexn: pullup enable for pin pxn ocxn: output control for pin pxn odxn: output data to pin pxn idxn: input data from pin pxn 0 1 dq from previous cell clockdr shiftdr to next cell from system pin to system logic ff1
at90scr100/116/132 374 tpr0327b ? vic ? 16fev11 27.7 at90scr100/116/132 boundary-scan order table 27-1 shows the scan order between tdi and tdo when the boundary-scan chain is selected as data path. bit 0 is the lsb; the first bit scanned in, and the first bit scanned out. the scan order follows the pin-out order as far as possible. therefore, the bits of port a and port k is scanned in the opposite bit order of the other port s. exceptions from the rules are the scan chains for the analog circuits, which constitute the most significant bits of the scan chain regard- less of which physical pin they are connected to. in figure 27-3 , pxn. data corresponds to ff0, pxn. control corresponds to ff1, pxn. bit 4, 5, 6 and 7 of port f is not in the scan chain, since these pins constitute the tap pins when the jtag is enabled. table 27-1. at90scr100/116/132 boundary-scan order bit number signal name module 68 pe0.data port e 67 pe0.control 66 pe1.data 65 pe1.control 64 pe2.data 63 pe2.control 62 pe3.data 61 pe3.control 60 pe4.data 59 pe4.control 58 pe5.data 57 pe5.control 56 pe6.data 55 pe6.control 54 pe7.data 53 pe7.control
375 tpr0327b ? vic ? 16fev11 27. ieee 1149.1 (jtag) boundary-scan at90scr100/116/132 52 pb0.data port b 51 pb0.control 50 pb1.data 49 pb1.control 48 pb2.data 47 pb2.control 46 pb3.data 45 pb3.control 44 pb4.data 43 pb4.control 42 pb5.data 41 pb5.control 40 pb6.data 39 pb6.control 38 pb7.data 37 pb7.control 36 rstt reset logic (observe only) 35 pd0.data port d 34 pd0.control 33 pd1.data 32 pd1.control 31 pd2.data 30 pd2.control 29 pd3.data 28 pd3.control 27 pd4.data 26 pd4.control 25 pd5.data 24 pd5.control 23 pd6.data 22 pd6.control 21 pd7.data 20 pd7.control table 27-1. at90scr100/116/132 boundary-scan order (continued) bit number signal name module
at90scr100/116/132 376 tpr0327b ? vic ? 16fev11 27.8 boundary-scan description language files boundary-scan description language (bsdl) files describe boundary-scan capable devices in a standard format used by automated test-generation software. the order and function of bits in the boundary-scan data register are included in this description. bsdl files are available for at90scr100/116/132. 19 pc0.data port c 18 pc0.control 17 pc1.data 16 pc1.control 15 pa7.data port a 14 pa7.control 13 pa6.data 12 pa6.control 11 pa5.data 10 pa5.control 9pa4.data 8 pa4.control 7pa3.data 6 pa3.control 5pa2.data 4 pa2.control 3pa1.data 2 pa1.control 1pa0.data 0 pa0.control table 27-1. at90scr100/116/132 boundary-scan order (continued) bit number signal name module
377 tpr0327b ? vic ? 16fev11 28. boot loader support - read-while-write at90scr100/116/132 28. boot loader support - read-w hile-write self-programming the boot loader support provides a real read-while-write self-programming mechanism to download and upload program code by the mcu itself. this feature allows flexible application software updates controlled by the mcu using a flash-resident boot loader program. the boot loader program can use any available data interface and associated protocol to read and/or write (program) code into the flash memory. the program code within the boot loader section has the capability to write into the entire flash, including the boot loader memory. thus, the boot loader can modify itself or erase itself from the code if the feature is not needed anymore. the size of the boot loader memory is configurable with fuses and the boot loader has two separate sets of boot lock bits which can be set independently. this gives the user a unique flexibility to select different levels of protection. 28.1 boot loader features ? read-while-write self-programming ? flexible boot memory size ? high security (separate boot lock bits for a flexible protection) ? separate fuse to select reset vector ? optimized page size ? code efficient algorithm ? efficient read-modify-write support 28.2 application and boot loader flash sections the flash memory is organized in two main sections, the application section and the boot loader section (see figure 28-2 ). the size of the different sections is configured by the bootsz fuses as shown in table 28-7 on page 390 and figure 28-2 . these two sections can have different level of protection because they have different sets of lock bits. 28.2.1 application section the application section is the section of the flash that is used to store the application code. the protection level for the application section can be selected by the application boot lock bits (boot lock bits 0), see table 28-2 on page 380 . the application section can never store any boot loader code because the spm instruction is disabled when executed from the application section. 28.2.2 bls ? boot loader section while the application section is used to store the application code, the the boot loader soft- ware must be located in the bls because the spm instruction can initiate a programming sequence when executing from the bls only. the spm instruction can access the entire flash, including the bls itself. the protection level for the boot loader section can be selected by the boot loader lock bits (boot lock bits 1), see table 28-3 on page 380 . note note a page is a section in the flash consisting of several bytes (see table 29-7 on page 395 ) used during programming sequence. the page organization does not affect normal operation.
at90scr100/116/132 378 tpr0327b ? vic ? 16fev11 28.3 read-while-write and no read-while-write flash sections regarding the address targeted by a progra mming sequence, the cpu supports read-while- write or is halted during a boot loader software update. in addition to the two sections that are configurable by the bootsz fuses as described above, the flash is also divided into two fixed secti ons, the read-while-write (rww) section and the no read-while-write (nrww) section. the limit between the rww- and nrww sections is given in table 28-1 and figure 28-1 on page 379 . the main differences between the two sec- tions are: ? the nrww section can be read when erasing or writing a page located inside the rww section. ? the cpu is stopped when erasing or writing a page located inside the nrww section. 28.3.1 rww ? read-while-write section if a boot loader software update is programming a page inside the rww section you can only read code from the nrww section. during an on-going programming, the software must ensure that the rww section won?t be read. if the user software is trying to read code located inside the rww section (i.e., by load pro- gram memory, call, or jump instructions or an interrupt) during programming sequence, the software may end up in an unknown state. to avoid this, the interrupts should either be disabled or moved to the boot loader section. the boot loader section is always located in the nrww section. the rww section busy bit (rwwsb) in the store program memory control and status register (spmcsr) will be read as logical one as long as the rww section is blocked for read operation. after the end of a pro- gramming sequence, the rwwsb must be cleared by software before reading code located in the rww section. see ?spmcsr ? store program memory control and status register? on page 381. for details on how to clear rwwsb. 28.3.2 nrww ? no read-while-write section the code located in the nrww section can be read when the boot loader software is updating a page in the rww section. when the boot loader code updates the nrww section, the cpu is halted during the entire page erase or page write operation. note note the user software can never read any code located inside the rww section dur- ing a boot loader software operation. the syntax ?read-while-write section? refers to the section that is being programmed (erased or written), not the section executed during a boot loader software update. table 28-1. read-while-write features which section does the z-pointer address during the programming? which section can be read during programming? is the cpu halted? read-while-write supported? rww section nrww section no yes nrww section none yes no
379 tpr0327b ? vic ? 16fev11 28. boot loader support - read-while-write at90scr100/116/132 figure 28-1. read-while-write vs. no read-while-write figure 28-2. memory sections note note the parameters in the figure above are given in table 28-7 on page 390 . read-while-write (rww) section no read-while-write (nrww) section z-pointer addresses rww section z-pointer addresses nrww section cpu is halted during the operatio n code located in nrww section can be read during the operation 0x0000 0x6fff 0x7000 0x7800 0x7c00 0x7e00 0x7fff program memory bootsz=11 application flash section boot loader flash section application flash section read-while-write section no read-while-write section bootsz=10 bootsz=01 start boot loader/end applicatio n limitation bootsz=00
at90scr100/116/132 380 tpr0327b ? vic ? 16fev11 28.4 boot loader lock bits if no boot loader capability is needed, the entire flash is available for application code. the boot loader has two separate sets of boot lock bits which can be set independently. this gives the user a unique flexibility to select different levels of protection. the user can select: ? to protect the entire flash from a software update by the mcu. ? to protect only the boot loader flash section from a software update by the mcu. ? to protect only the application flash section from a software update by the mcu. ? allow software update in the entire flash. see table 28-2 and table 28-3 for further details. the boot lock bits can be set in software and in serial pogramming mode, but they can be cleared by a chip erase command only. the gen- eral write lock (lock bit mode 2) does not control the programming of the flash memory by spm instruction. similarly, the general read/write lock (lock bit mode 1) does not control read- ing nor writing by (e)lpm/spm, if it is attempted. note: 1. ?1? means unprogrammed, ?0? means programmed table 28-2. boot lock bit0 protection modes (application section) (1) blb0 mode blb02 blb01 protection 111 no restrictions for spm or (e)lpm accessing the application section. 2 1 0 spm is not allowed to write to the application section. 300 spm is not allowed to write to the application section, and (e)lpm executing from the boot loader section is not allowed to read from the application section. if interrupt vectors are placed in the boot loader section, interrupts are disabled while executing from the application section. 401 (e)lpm executing from the boot loader section is not allowed to read from the application section. if interrupt vectors are placed in the boot loader section, interrupts are disabled while executing from the application section. table 28-3. boot lock bit1 protection modes (boot loader section) (1) blb1 mode blb12 blb11 protection 111 no restrictions for spm or (e )lpm accessing the boot loader section. 2 1 0 spm is not allowed to write to the boot loader section. 300 spm is not allowed to write to the boot loader section, and (e)lpm executing from the application section is not allowed to read from the boot loader section. if interrupt vectors are placed in the application section, interrupts are disabled while executing from the boot loader section. 401 (e)lpm executing from the application section is not allowed to read from the boot loader section. if interrupt vectors are placed in the application section, interrupts are disabled while executing from the boot loader section.
381 tpr0327b ? vic ? 16fev11 28. boot loader support - read-while-write at90scr100/116/132 28.5 entering the boot loader program entering the boot loader takes place by a jump or call from the application program. this may be initiated by a trigger such as a command received via usart, or spi interface. alternatively, the boot reset fuse can be programmed so that the reset vector is pointing to the boot flash start address after a reset. in this case, the boot loader is started after a reset. after the applica- tion code is loaded, the program can start execut ing the application code. note that the fuses cannot be changed by the mcu itself. this means that once the boot reset fuse is pro- grammed, the reset vector will always point to the boot loader reset and the fuse can only be changed through the serial programming interface. note: 1. ?1? means unprogrammed, ?0? means programmed 28.5.1 spmcsr ? store program memory control and status register the store program memory control and status register contains the control bits needed to con- trol the boot loader operations. ? bit 7 ? spmie: spm interrupt enable if the spmie bit is set (one), and if the i-bit in the status register is set (one), the spm ready interrupt will be enabled. the spm ready interrupt will remain activated as long as the spmen bit in the spmcsr regis- ter is cleared (zero). ? bit 6 ? rwwsb: read-while-write section busy when a self-programming (page erase or page write) operation to the rww section is initi- ated, the rwwsb will be set (one) by hardware. when the rwwsb bit is set, the rww section cannot be accessed. the rwwsb bit will be cleared if the rwwsre bit is written to one after a self-programming operation is completed. alternatively the rwwsb bit will automatically be cleared if a page load operation is initiated. ? bit 5 ? sigrd: signature row read if this bit is written to one at the same time as spmen, the next lpm instruction within three clock cycles will read a byte from the signat ure row into the dest ination register. see ?reading the signature row from software? on page 387 for details. an spm instruction within four cycles after sigrd and spmen are set will have no effec t. this operation is reserved for future use and should not be used. ? bit 4 ? rwwsre: read-while-write section read enable table 28-4. boot reset fuse (1) bootrst reset address 1 reset vector = application reset (address 0x0000) 0 reset vector = boot loader reset (see table 28-7 on page 390 ) bit 76543 2 10 0x37 (0x57) spmie rwwsb sigrd rwwsre blbset pgwrt pgers spmen spmcsr read/write r/w r r/w r/w r/w r/w r/w r/w initial value 0 0 0 1 0 0 0 0 0x00
at90scr100/116/132 382 tpr0327b ? vic ? 16fev11 when programming (page erase or page write) to the rww section, the rww section is blocked for reading (the rwwsb will be set by hardware). to re-enable the rww section, the user software must wait until the programming is completed (spmen will be cleared). then, if the rwwsre bit is written to one at the same time as spmen, the next spm instruction within four clock cycles re-enables the rww secti on. the rww section cannot be re-enabled while the flash is busy with a page erase or a page write (spmen is set). if the rwwsre bit is writ- ten while the flash is being loaded, the flash load operation will abort and the data loaded will be lost. ? bit 3 ? blbset: boot lock bit set if this bit is set (one) at the same time as spmen, the next spm instruction within four clock cycles sets boot lock bits, according to the data in r0. the data in r1 and the address in the z- pointer are ignored. the blbset bit will automatically be cleared upon completion of the lock bit set operation, or if no spm instruction is executed within four clock cycles. an (e)lpm instruction within three cycles after blbset and spmen are set in the spmcsr register, will read either the lock bits or the fuse bits (depending on z0 in the z-pointer) into the destination register. see ?reading the fuse and lock bits from software? on page 386 for details. ? bit 2 ? pgwrt: page write if this bit is set (one)at the same time as spmen, the next spm instruction within four clock cycles executes page write, with the data stor ed in the temporary buffer. the page address is taken from the high part of the z-pointer. the data in r1 and r0 are ignored. the pgwrt bit will be automatically cleared upon completion of a page write, or if no spm instruction is exe- cuted within four clock cycles. the cpu is halted during the entire page write operation if the nrww section is addressed. ? bit 1 ? pgers: page erase if this bit is set (one) at the same time as spmen, the next spm instruction within four clock cycles executes page erase. the page address is taken from the high part of the z-pointer. the data in r1 and r0 are ignored. the pgers bit will be automatically cleared upon completion of a page erase, or if no spm instruction is executed within four clock cycles. the cpu is halted during the entire page write operation if the nrww section is addressed. ? bit 0 ? spmen: store program memory enable this bit enables the spm instruction for the next four clock cycles. if written to one together with either rwwsre, blbset, pgwrt? or pgers, the following spm instruction will have a spe- cial meaning, see description above. if only spmen is written, the following spm instruction will store the value of r1:r0 in the temporary page buffer addressed by the z-pointer. the lsb of the z-pointer is ignored. the spmen bit will be automatically cleared upon completion of an spm instruction, or if no spm instruction is executed within four clock cycles. during page erase and page write, the spmen bit remains high until the operation is completed. writing any other combination than ?10001?, ?01001?, ?00101?, ?00011? or ?00001? in the lower five bits will have no effect. note note only one spm instruction should be active at any time.
383 tpr0327b ? vic ? 16fev11 28. boot loader support - read-while-write at90scr100/116/132 28.6 addressing the flash during self-programming the z-pointer is used to address the spm commands. the z pointer consists of the z-registers zl and zh in the register file. the number of bits actually used is implementation dependent. since the flash is organized in pages (see table 29-7 on page 395 ), the program counter can be treated as having two different sections. one section, consisting of the least significant bits, is addressing the words within a page, while the most significant bits are addressing the pages. this is shown in figure 28-3 . note that the page erase and page write operations are addressed independently. therefore it is of major importance that the boot loader software addresses the same page in both the page erase and page write operation. once a program- ming operation is initiated, the address is la tched and the z-pointer can be used for other operations. the (e)lpm instruction use the z-pointer to store the address. since this instruction addresses the flash byte-by-byte, also bit z0 of the z-pointer is used. figure 28-3. addressing the flash during spm bit 1514131211 10 7 8 zh (r31) z15 z14 z13 z12 z11 z10 z9 z8 zh (r30) z7 z6 z5 z4 z3 z2 z1 z0 76543 2 10 note note only one spm instruction should be active at any time. program memory 0 1 15 z - register bit 0 zpagemsb word address within a page page address within the flash zpcmsb instruction word page pcword[pagemsb:0]: 00 01 02 pageend page pcword pcpage pcmsb pagemsb program counter
at90scr100/116/132 384 tpr0327b ? vic ? 16fev11 28.7 self-programming the flash the program memory is updated page by page. before programming a page with the data stored in the temporary page buffer, the page must be erased. the temporary page buffer is filled one word per word using spm instruction and the buffer can be filled either before the page erase command or between a page erase and a page write operation: alternative 1, fill the buffer before a page erase ? fill temporary page buffer ? perform a page erase ? perform a page write alternative 2, fill the buffer after page erase ? perform a page erase ? fill temporary page buffer ? perform a page write if only a part of the page needs to be changed, the rest of the page must be stored (for example in the temporary page buffer) before the erase, and then be rewritten. when using alternative 1, the boot loader provides an effective read-modify-write feature which allows the user software to first read the page, do the necessary changes, and then write back the modified data. if alter- native 2 is used, it is not possible to read the old data while loading because the page is already erased. the temporary page buffer can be accessed in a random sequence. it is essential that the page address used in both the page erase and page write operation is addressing the same page. see ?simple assembly code example for a boot loader? on page 388 for an assembly code example. 28.7.1 performing page erase by spm to execute page erase, set up the address in the z-pointer, write ?x0000011? to spmcsr and execute spm within four clock cycles after writing spmcsr. the data in r1 and r0 are ignored. the page address must be written to pcpage in the z-register. other bits in the z-pointer will be ignored during this operation. ? page erase to the rww section: the nrww section can be read during the page erase. ? page erase to the nrww section: the cpu is halted during the operation. 28.7.2 filling the temporary buffer (page loading) to write an instruction word, set up the address in the z-pointer and data in r1:r0, write ?00000001? to spmcsr and execute spm within four clock cycles after writing spmcsr. the content of pcword in the z-register is used to address the data in the temporary buffer. the temporary buffer will be automatically erased after a page write operation or by writing the rwwsre bit in spmcsr. it is also erased after a system reset. note that it is not possible to write more than one time to each address without erasing the temporary buffer. if the eeprom is written in the middle of an spm page load operation, all data loaded will be lost.
385 tpr0327b ? vic ? 16fev11 28. boot loader support - read-while-write at90scr100/116/132 28.7.3 performing a page write to execute page write, set up the address in the z-pointer, write ?x0000101? to spmcsr and execute spm within four clock cycles after writing spmcsr. the data in r1 and r0 is ignored. the page address must be written to pcpage. other bits in the z-pointer must be written to zero during this operation. ? page write to the rww section: the nrww section can be read during the page write. ? page write to the nrww section: the cpu is halted during the operation. 28.7.4 using the spm interrupt if the spm interrupt is enabled, the spm interrupt will generate a constant interrupt when the spmen bit in spmcsr is cleared. this means that the interrupt can be used instead of polling the spmcsr register in software. when using the spm interrupt, the interrupt vectors should be moved to the bls section to avoid that an interrupt is accessing the rww section when it is blocked for reading. how to move the interrupts is described in ?interrupts? on page 71 . 28.7.5 consideration while updating bls special care must be taken if the user allows the boot loader section to be updated by leaving boot lock bit11 unprogrammed. an accidental write to the boot loader itself can corrupt the entire boot loader, and further software updates might be impossible. if it is not necessary to change the boot loader software itself, it is recommended to program the boot lock bit11 to protect the boot loader software from any internal software changes. 28.7.6 prevent reading the rww section during self-programming during self-programming (either page erase or page write), the rww section is always blocked for reading. the user software itself must prevent that this section is addressed during the self programming operation. the rwwsb in the spmcsr will be set as long as the rww section is busy. during self-programming the interrupt vector table should be moved to the bls as described in ?interrupts? on page 71 , or the interrupts must be disabled. before addressing the rww section after the programming is completed, the user software must clear the rwwsb by writing the rwwsre. see ?simple assembly code example for a boot loader? on page 388 for an example. 28.7.7 setting the boot loader lock bits by spm to set the boot loader lock bits and general lock bits, write the desired data to r0, write ?x0001001? to spmcsr and execute spm within four clock cycles after writing spmcsr. see table 28-2 and table 28-3 for how the different settings of the boot loader bits affect the flash access. if bits 5..0 in r0 are cleared (zero), the corresponding lock bit will be programmed if an spm instruction is executed within four cycles after blbset and spmen are set in spmcsr. the z- pointer is not used during this operation, but for future compatibility it is recommended to load the z-pointer with 0x0001 value (same as used for reading the lo ck bits). for future compatibility it is also recommended to set bits 7 and 6 in r0 to ?1? when writing the lock bits. when pro- gramming the lock bits the entire flash can be read during the operation. bit 76543 2 10 r0 1 1 blb12 blb11 blb02 blb01 lb2 lb1
at90scr100/116/132 386 tpr0327b ? vic ? 16fev11 28.7.8 eeprom write prevents writing to spmcsr note that an eeprom write operation will block all software programming to flash. reading the fuses and lock bits from software will also be prevented during the eeprom write operation. it is recommended that the user checks the status bit (eepe) in the eecr register and verifies that the bit is cleared before writing to the spmcsr register. 28.7.9 reading the fuse and lock bits from software it is possible to read both the fuse and lock bits from software. to read the lock bits, load the z-pointer with 0x0001 and set the blbset and spmen bits in spmcsr. when an (e)lpm instruction is executed within three cpu cycles after the blbset and spmen bits are set in spmcsr, the value of the lock bits will be loaded in the destination register. the blbset and spmen bits will auto-clear upon completion of reading the lock bits or if no (e)lpm instruction is executed within three cpu cycles or no spm instruction is executed within four cpu cycles. when blbset and spmen are cleared, (e)lpm will work as described in the instruction set manual. the algorithm for reading the fuse low byte is similar to the one described above for reading the lock bits. to read the fuse low byte, load the z-pointer with 0x0000 and set the blbset and spmen bits in spmcsr. when an (e)lpm instruction is executed within three cycles after the blbset and spmen bits are set in the spmcsr, the value of the fuse low byte (flb) will be loaded in the destination register as shown below. refer to table 29-5 on page 394 for a detailed description and mapping of the fuse low byte. similarly, when reading the fuse high byte , load 0x0003 in the z-pointer. when an (e)lpm instruction is executed within three cycles after the blbset and spmen bits are set in the spmcsr, the value of the fuse high byte (fhb) will be loaded in the destination register as shown below. refer to table 29-4 on page 393 for detailed description and mapping of the fuse high byte. when reading the extended fuse byte, load 0x0002 in the z-pointer. when an (e)lpm instruc- tion is executed within three cycles after the blbset and spmen bits are set in the spmcsr, the value of the extended fuse byte (efb) will be loaded in the destinati on register as shown below. refer to table 29-3 on page 393 for detailed description and mapping of the extended fuse byte. fuse and lock bits that are programmed, will be read as zero. fuse and lock bits that are unprogrammed, will be read as one. bit 76543 2 10 rd - - blb12 blb11 blb02 blb01 lb2 lb1 bit 76543 2 10 rd flb7 flb6 flb5 flb4 flb3 flb2 flb1 flb0 bit 76543 2 10 rd fhb7 fhb6 fhb5 fhb4 fhb3 fhb2 fhb1 fhb0 bit 76543 2 10 rd -----efb2efb1efb0
387 tpr0327b ? vic ? 16fev11 28. boot loader support - read-while-write at90scr100/116/132 28.7.10 reading the signature row from software to read the signature row from software, load the z-pointer with the signature byte address given in table 28-5 on page 387 and set the sigrd and spmen bits in spmcsr. when an lpm instruction is executed within three cpu cycles after the sigrd and spmen bits are set in spmcsr, the signature byte value will be loaded in the destination register. the sigrd and spmen bits will auto-clear upon completion of reading the signature row lock bits or if no lpm instruction is executed within three cpu cycles. when sigrd and spmen are cleared, lpm will work as described in the instruction set manual. note: 1. all other addresses are reserved for future use. 28.7.11 preventing flash corruption during periods of low v cc , the flash program can be corrupted because the supply voltage is too low for the cpu and the flash to operate properly. these issues are the same as for board level systems using the flash, and the same design solutions should be applied. a flash program corruption can be caused by two situations when the voltage is too low. first, a regular write sequence to the flash requires a minimum voltage to operate correctly. secondly, the cpu itself can execute instructions incorrectly, if the supply voltage for executing instructions is too low. flash corruption can easily be avoided by following these design recommendations (one is sufficient): 1. if there is no need for a boot loader update in the system, program the boot loader lock bits to prevent any boot loader software updates. 2. keep the avr reset active (low) during periods of insufficient power supply voltage. this can be done by enabling the internal brown-out detector (bod) if the operating voltage matches the detection level. if not, an external low v cc reset protection circuit can be used. if a reset occurs while a write operation is in progress, the write operation will be completed provided that the power supply voltage is sufficient. table 28-5. signature row addressing (1) signature byte z-pointer address device signature byte 1 0x0000 device signature byte 2 0x0002 device signature byte 3 0x0004 rc oscillator calibration byte 0x0001 serial number byte 0 0x0006 serial number byte 1 0x0008 serial number byte 2 0x000a serial number byte 3 0x000c serial number byte 4 0x000e serial number byte 5 0x0010 serial number byte 6 0x0012 serial number byte 7 0x0014 serial number byte 8 0x0016
at90scr100/116/132 388 tpr0327b ? vic ? 16fev11 3. keep the 8/16-bit risc cpu core in power-down sleep mode during periods of low v cc . this will prevent the cpu from attempting to decode and execute instructions, effectively protecting the spmcsr register and thus the flash from unintentional writes. 28.7.12 programming time for flash when using spm the calibrated rc oscillator is used to time flash accesses. table 28-6 shows the typical pro- gramming time for flash accesses from the cpu. 28.7.13 simple assembly code example for a boot loader ;-the routine writes one page of data from ram to flash ; the first data location in ram is pointed to by the y pointer ; the first data location in flash is pointed to by the z-pointer ;-error handling is not included ;-the routine must be placed inside the boot space ; (at least the do_spm sub routine). only code inside nrww section can ; be read during self-programming (page erase and page write). ;-registers used: r0, r1, temp1 (r16), temp2 (r17), looplo (r24), ; loophi (r25), spmcrval (r20) ; storing and restoring of registers is not included in the routine ; register usage can be optimized at the expense of code size ;-it is assumed that either the interrupt table is moved to the boot ; loader section or that the interrupts are disabled. .equ pagesizeb = pagesize*2 ;pagesizeb is page size in bytes, not words .org smallbootstart write_page: ; page erase ldi spmcrval, (1< 389 tpr0327b ? vic ? 16fev11 28. boot loader support - read-while-write at90scr100/116/132 ; execute page write subi zl, low(pagesizeb) ;restore pointer sbci zh, high(pagesizeb) ;not required for pagesizeb<=256 ldi spmcrval, (1< at90scr100/116/132 390 tpr0327b ? vic ? 16fev11 28.7.14 at90scr100/116/132 boot loader parameters in table 28-7 through table 28-9 , the parameters used in the description of the self-program- ming are given. the different bootsz fuse configurations are shown in figure 28-2 . note: 1. for details about these two section, see ?nrww ? no read-while-write section? on page 378 and ?rww ? read- while-write section? on page 378 . note: 1. z0: should be zero for all spm commands, byte select for the (e)lpm instruction. see ?addressing the flash during self-programming? on page 383 for details about the use of z-pointer during self-programming. table 28-7. boot size configuration bootsz1 bootsz0 boot size pages application flash section boot loader flash section end application section boot reset address (start boot loader section) 1 1 512 words 4 0x0000 - 0x7dff 0x7e00 - 0x7fff 0x7dff 0x7e00 1 0 1024 words 8 0x0000 - 0x7bff 0x7c00 - 0x7fff 0x7bff 0x7c00 0 1 2048 words 16 0x0000 - 0x77ff 0x7800 - 0x7fff 0x77ff 0x7800 0 0 4096 words 32 0x0000 - 0x6fff 0x7000 - 0x7fff 0x6fff 0x7000 table 28-8. read-while-write limit (1) section pages address read-while-write section (rww) 224 0x0000 - 0x6fff no read-while-write section (nrww) 32 0x7000 - 0x7fff table 28-9. explanation of different variables used in figure 28-3 and the mapping to the z-pointer variable correspondig z-value description (1) pcmsb 14 most significant bit in the program counter. (the program counter is 15 bits pc[14:0]) pagemsb 7 most significant bit which is used to address the words within one page (128 words in a page requires seven bits pc [6:0]). zpcmsb z15 bit in z-pointer that is mapped to pcmsb. because z0 is not used, the zpcmsb equals pcmsb + 1. zpagemsb z8 bit in z-pointer that is mapped to pcmsb. because z0 is not used, the zpagemsb equals pagemsb + 1. pcpage pc[14:7] z15:z7 program counter page address: page select, for page erase and page write pcword pc[6:0] z7:z1 program counter word address: word select, for filling temporary buffer (must be zero during page write operation)
391 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 29. memory programming 29.1 program and data memory lock bits the at90scr100/116/132 provides six lock bits which can be left unprogrammed (?1?) or can be programmed (?0?) to obtain the additional features listed in table 29-2 . the lock bits can only be erased to ?1? with the chip erase command. notes: 1. ?1? means unprogrammed, ?0? means programmed table 29-1. lock bit byte (1) lock bit byte bit no description default value ? 7 ? 1 (unprogrammed) ? 6 ? 1 (unprogrammed) blb12 5 boot lock bit 1 (unprogrammed) blb11 4 boot lock bit 1 (unprogrammed) blb02 3 boot lock bit 1 (unprogrammed) blb01 2 boot lock bit 1 (unprogrammed) lb2 1 lock bit 1 (unprogrammed) lb1 0 lock bit 1 (unprogrammed)
at90scr100/116/132 392 tpr0327b ? vic ? 16fev11 notes: 1. program the fuse bits and boot lock bits before programming the lb1 and lb2. table 29-2. lock bit protection modes (1) memory lock bits protection type lb mode lb2 lb1 1 1 1 no memory lock features enabled. 210 further programming of the flash and eeprom is disabled in serial programming mode. the fuse bits are locked in serial programming mode. 300 further programming and verification of the flash and eeprom is disabled in serial programming mode. the boot lock bits and fuse bits are locked in both serial programming mode. blb0 mode blb02 blb01 111 no restrictions for spm or (e)lpm accessing the application section. 2 1 0 spm is not allowed to write to the application section. 300 spm is not allowed to write to the application section, and (e)lpm executing from the boot loader section is not allowed to read from the application section. if interrupt vectors are placed in the boot loader section, interrupts are disabled while executing from the application section. 401 (e)lpm executing from the boot loader section is not allowed to read from the application section. if interrupt vectors are placed in the boot loader section, interrupts are disabled while executing from the application section. blb1 mode blb12 blb11 111 no restrictions for spm or (e )lpm accessing the boot loader section. 2 1 0 spm is not allowed to write to the boot loader section. 300 spm is not allowed to write to the boot loader section, and (e)lpm executing from the application section is not allowed to read from the boot loader section. if interrupt vectors are placed in the application section, interrupts are disabled while executing from the boot loader section. 401 (e)lpm executing from the application section is not allowed to read from the boot loader section. if interrupt vectors are placed in the application section, interrupts are disabled while executing from the boot loader section.
393 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 29.2 fuse bits the at90scr100/116/132 has four fuse bytes. table 29-3 - table 29-5 describe briefly the functionality of all the fuses and how they are mapped into the fuse bytes. note that the fuses are read as logical zero, ?0?, if they are programmed. notes: 1. refer to table 9-2 on page 62 to get decoding of bodenable bit. notes: 1. never ship a product with the ocden fuse programmed regardless of the setting of lock bits and jtagen fuse. a programmed ocden fuse enables some parts of the clock system to be running in all sleep modes. this may increase the power consumption. 2. the spien fuse is not accessible in serial programming mode. 3. see ?wdtcsr ? watchdog timer control register? on page 69 for details. 4. the default value of bootsz1..0 results in maximum boot size. see table 28-7 on page 390 for details table 29-3. extended fuse byte fuse low byte bit no description default value ?7? 1 ?6? 1 ?5? 1 ?4? 1 ?3? 1 ?2? 1 ?1? 1 bodenable (1) 0 brown-out detector enable control 0 (unprogrammed) table 29-4. fuse high byte fuse high byte bit no description default value ocden (1) 7 enable ocd 1 (unprogrammed, ocd disabled) jtagen 6 enable jtag 0 (programmed, jtag enabled) spien (2) 5 enable serial program and data downloading 0 (programmed, spi prog. enabled) wdton (3) 4 watchdog timer always on 1 (unprogrammed) eesave 3 eeprom memory is preserved through the chip erase 1 (unprogrammed, eeprom not preserved) bootsz1 2 select boot size (see table 28-7 for details) 0 (programmed) (4) bootsz0 1 select boot size (see table 28-7 for details) 0 (programmed) (4) bootrst 0 select reset vector 1 (unprogrammed)
at90scr100/116/132 394 tpr0327b ? vic ? 16fev11 notes: 1. the ckout fuse allow the system clock to be output on portb1. see ?clock output buffer? on page 48 for details. 2. the default value of sut1..0 results in maximum start-up time for the default clock source. see table 7-3 on page 45 for details. 3. these values are fixed. they used to select clocks that are not available for at90scr100/116/132. the status of the fuse bits is not affected by chip erase. note that the fuse bits are locked if lock bit1 (lb1) is programmed. program the fuse bits before programming the lock bits. 29.2.1 latching of fuses the fuse values are latched when the device enters programming mode and changes of the fuse values will have no effect until the part leaves programming mode. this does not apply to the eesave fuse which will take effect once it is programmed. the fuses are also latched on power-up in normal mode. 29.3 signature bytes 29.3.1 device and jtag ids all inside secure microcontrollers have a three-byte signature code which identifies the device. this code can be read in both serial and parallel mode, also when the device is locked. the three bytes reside in a separate address space. the at90scr100/116/132 signature bytes are given in table 29-6 . 29.3.2 serial number the serial number is composed of 9 bytes. you can only read these bytes. they are pro- grammed during probe sessions and are unique for each die. they are composed of: ? sn0: chip id: same for all at90scr100/116/132 ics table 29-5. fuse low byte fuse low byte bit no description default value -7- 1 ckout (1) 6 clock output 1 (unprogrammed) sut1 5 select start-up time 1 (unprogrammed) (2) sut0 4 select start-up time 0 (programmed) (2) cksel3 3 select clock source 1 (unprogrammed) -2- 0 (3) -1- 0 (3) cksel0 0 select clock source 1 (unprogrammed) table 29-6. device and jtag id part signature bytes address jtag 0x000 0x001 0x002 part number manufacture id at90scr100/116/ 132 0x1e 0x96 0xc1 96c1 0x1f
395 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 ? sn1: silicon revision ? sn2: production year ? sn3: fab & quarter ? sn4: lot number high order byte ? sn5: lot number low order byte ? sn6: wafer number within the lot ? sn7: chip number (on the wafer) low order byte (row number) ? sn8: chip number (on the wafer) high order byte (column number) 29.4 calibration byte the at90scr100/116/132 has a byte calibration value for the internal rc oscillator. this byte resides in the high byte of address 0x000 in the signature address space. during reset, this byte is automatically written into the internal calibration register to ensure correct frequency of the calibrated rc oscillator. 29.5 page size 29.6 serial downloading both the flash and eeprom memory arrays can be programmed using a serial programming bus while reset is pulled to gnd. the serial programming interface consists of pins sck, mosi (input) and miso (output). after reset is set low, the programming enable instruction needs to be executed first before program/erase operations can be executed. 29.6.1 serial programming pin mapping table 29-7. no. of words in a page and no. of pages in the flash device flash size page size pcword no. of pages pcpage pcmsb at90scr100/1 16/132 32k words (64 kbytes) 128 words pc[6:0] 256 pc[14:7] 14 table 29-8. no. of words in a page and no. of pages in the eeprom device eeprom size page size pcword no. of pages pcpage eeamsb at90scr100/1 16/132 4 kbytes 32 bytes eea[2:0] 128 eea[10:3] 10 table 29-9. pin mapping serial programming symbol pins i/o description mosi pb5 i serial data in miso pb6 o serial data out sck pb7 i serial clock
at90scr100/116/132 396 tpr0327b ? vic ? 16fev11 figure 29-1. serial programming and verify when programming the eeprom, an auto-erase cycle is built into the self-timed programming operation (in the serial mode only) and ther e is no need to first execute the chip erase instruction. the chip erase operation turns the content of every memory location in both the program and eeprom arrays into 0xff. depending on cksel fuses, a valid clock must be present. the minimum low and high periods for the serial clock (sck) input are defined as follows: low: > 2 cpu clock cycles for f ck < 12 mhz, 3 cpu clock cycles for f ck >= 12 mhz high: > 2 cpu clock cycles for f ck < 12 mhz, 3 cpu clock cycles for f ck >= 12 mhz 29.6.2 serial programming algorithm when writing serial data to the at90scr100/116/132, data is clocked on the rising edge of sck. when reading data from the at90scr100/116/132, data is clocked on the falling edge of sck. see figure 29-3 for timing details. to program and verify the at90scr100/116/132 in the serial programming mode, the following sequence is recommended (see four byte instruction formats in table 29-11 ): 1. power-up sequence: apply power between v cc and gnd while reset and sck are set to ?0?. in some sys- tems, the programmer can not guarantee that sck is held low during power-up. in this case, reset must be given a positive pulse of at least two cpu clock cycles duration after sck has been set to ?0?. 2. wait for at least 20 ms and enable serial programming by sending the programming enable serial instruction to pin mosi. 3. the serial programming instructions will not work if the communication is out of syn- chronization. when in sync. the second byte (0x53), will echo back when issuing the third byte of the programming enable instruction. whether the echo is correct or not, all four bytes of the instruction must be transmitted. if the 0x53 did not echo back, give reset a positive pulse and issue a new programming enable command. 4. the flash is programmed one page at a time. the memory page is loaded one byte at a time by supplying the 7 lsb of the address and data together with the load program memory page instruction. to ensure correct loading of the page, the data low byte must be loaded before data high byte is applied for a given address. the program vcc gnd xtal1 sck miso mosi reset +1.8 - 5.5v avcc +1.8 - 5.5v ( 2
397 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 memory page is stored by loading the write program memory page instruction with the address lines 15..8. before issuing this command, make sure the instruction load extended address byte has been used to define the msb of the address. the extended address byte is stored until the command is re-issued, i.e., the command needs only be issued for the first page, and when crossing the 64k/32k/16k word boundary. if polling ( rdy/bsy ) is not used, the user must wait at least t wd_flash before issuing the next page. (see table 29-10 .) accessing the serial programming interface before the flash write operation completes can result in incorrect programming. 5. the eeprom array is programmed one byte at a time by supplying the address and data together with the appropriate write instruction. an eeprom memory location is first automatically erased before new data is written. if polling is not used, the user must wait at least t wd_eeprom before issuing the next byte. (see table 29-10 .) in a chip erased device, no 0xffs in the data file(s) need to be programmed. 6. any memory location can be verified by using the read instruction which returns the content at the selected address at serial output miso. when reading the flash mem- ory, use the instruction load extended address byte to define the upper address byte, which is not included in the read program memory instruction. the extended address byte is stored until the command is re-issued, i.e., the command needs only be issued for the first page, and when crossing the 64k/32k/16k word boundary. 7. at the end of the programming session, reset can be set high to commence normal operation. 8. power-off sequence (if needed): set reset to ?1?. turn v cc power off. 29.7 serial programming instruction set table 29-11 on page 397 and figure 29-2 on page 399 describes the instruction set. table 29-10. minimum wait delay before writing the next flash or eeprom location symbol minimum wait delay t wd_flash 4.5 ms t wd_eeprom 9.0 ms t wd_erase 9.0 ms table 29-11. serial programming instruction set (hexadecimal values) instruction/operation instruction format byte 1 byte 2 byte 3 byte4 programming enable $ac $53 $00 $00 chip erase (program memory/eeprom) $ac $80 $00 $00 poll rdy/bsy $f0 $00 $00 data byte out load instructions load extended address byte (1) $4d $00 extended adr $00 load program memory page, high byte $48 $00 adr lsb high data byte in load program memory page, low byte $40 $00 adr lsb low data byte in load eeprom memory page (page access) $c1 $00 0000 000aa (2) data byte in read instructions
at90scr100/116/132 398 tpr0327b ? vic ? 16fev11 notes: 1. not all instructions are applicable for all parts. 2. a = address if the lsb in rdy/bsy data byte out is ?1?, a programming operation is still pending. wait until this bit returns ?0? before the next instruction is carried out. within the same page, the low data byte must be loaded prior to the high data byte. after data is loaded to the page buffer, program the eeprom page, see figure 29-2 on page 399 . read program memory, high byte $28 adr msb adr lsb high data byte out read program memory, low byte $20 adr msb adr lsb low data byte out read eeprom memory $a0 0000 00aa (2) aaaa aaaa (2) data byte out read lock bits $58 $00 $00 data byte out read signature byte $30 $00 0000 aaaa (2) data byte out read fuse bits $50 $00 $00 data byte out read fuse high bits $58 $08 $00 data byte out read extended fuse bits $50 $08 $00 data byte out read calibration byte $38 $00 $00 data byte out write instructions write program memory page $4c adr msb adr lsb $00 write eeprom memory $c0 0000 00aa (2) aaaa aaaa (2) data byte in write eeprom memory page (page access) $c2 0000 00aa (2) aaaa aa00 (2) $00 write lock bits $ac $e0 $00 data byte in write fuse bits $ac $a0 $00 data byte in write fuse high bits $ac $a8 $00 data byte in write extended fuse bits $ac $a4 $00 data byte in table 29-11. serial programming instruction set (hexadecimal values) instruction/operation instruction format byte 1 byte 2 byte 3 byte4 note note 1. bits are programmed ?0?, unprogrammed ?1?. 2. to ensure future compatibility, unused fuses and lock bits should be unprogrammed (?1?) . 3. refer to the correspondig section for fuse and lock bits, calibration and signature bytes and page size. 4. see http://www.insidesecure.com/eng/products/smart-card-read- ers/contact for application notes regarding programming and programmers.
399 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 figure 29-2. serial programming instruction example 29.7.1 serial programming characteristics for characteristics of the serial programming module. see ?spi timing characteristics? on page 426. figure 29-3. serial programming waveforms 29.8 programming via the jtag interface programming through the jtag interface requires control of the four jtag specific pins: tck, tms, tdi, and tdo. control of the reset and clock pins is not required. to be able to use the jtag interface, the jt agen fuse must be programmed. the device is default shipped with the fuse programmed. in addition, the jtd bit in mcucsr must be cleared. alternatively, if the jtd bit is set, the external reset can be forced low. then, the jtd bit will be cleared after two chip clocks, and the jtag pins are available for programming. this provides a means of using the jtag pins as normal port pins in running mode while still allowing in-sys- byte 1 byte 2 byte 3 byte 4 adr msb adr lsb bit 15 b 0 serial programming instruction program memory/ eeprom memory page 0 page 1 page 2 page n-1 page buffer write program memory page/ write eeprom memory page load program memory page (high/low byte)/ load eeprom memory page (page access) byte 1 byte 2 byte 3 byte 4 bit 15 b 0 adr msb adr lsb page offset page number ad r m ms sb a a adr r l lsb b msb msb lsb lsb serial clock input (sck) serial data input (mosi) (miso) sample serial data output
at90scr100/116/132 400 tpr0327b ? vic ? 16fev11 tem programming via the jtag interface. note that this technique can not be used when using the jtag pins for boundary-scan or on-chip debug. in these cases the jtag pins must be ded- icated for this purpose. during programming the clock frequency of the tck input must be less than the maximum fre- quency of the chip. the system clock prescaler can not be used to divide the tck clock input into a sufficiently low frequency. as a definition in this datasheet, the lsb is shifted in and out first of all shift registers. 29.8.1 programming specific jtag instructions the instruction register is 4-bit wide, supporting up to 16 instructions. the jtag instructions useful for programming are listed below. the opcode for each instruction is shown behind the instruction name in hex format. the text describes which data register is selected as path between tdi and tdo for each instruction. the run-test/idle state of the tap controller is used to generate internal clocks. it can also be used as an idle state between jtag sequences. the state machine sequence for changing the instruction word is shown in figure 29-4 . figure 29-4. state machine sequence to change the instruction word test-logic-reset run-test/idle shift-dr exit1-dr pause-dr exit2-dr update-dr select-ir scan capture-ir shift-ir exit1-ir pause-ir exit2-ir update-ir select-dr scan capture-dr 0 1 0 11 1 00 00 11 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1
401 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 29.8.2 avr_reset (0xc) the 8/16-bit risc cpu specific public jtag instruction to set the 8/16-bit risc cpu device in the reset mode or to take the device out from the reset mode. the tap controller is not reset by this instruction. the one bit reset register is selected as data register. note that the reset will be active as long as there is a logic ?one? in the reset chain. the output from this chain is not latched. the active states are: ? shift-dr: the reset register is shifted by the tck input. 29.8.3 prog_enable (0x4) the 8/16-bit risc cpu specific public jtag instruction to enable the programming via the jtag port. the 16-bit programming enable register is selected as data register. the active states are the following: ? shift-dr: the programming enable signature is shifted into the data register. ? update-dr: the programming enable signature is compared to the correct value, and programming mode is entered if the signature is valid. 29.8.4 prog_commands (0x5) the 8/16-bit risc cpu specific public jtag instruction for entering programming commands via the jtag port. the 15-bit programming command register is selected as data register. the active states are the following: ? capture-dr: the result of the previous command is loaded into the data register. ? shift-dr: the data register is shifted by the tck input, shifting out the result of the previous command and shifting in the new command. ? update-dr: the programming command is applied to the flash inputs ? run-test/idle: one clock cycle is generated, executing the applied command 29.8.5 prog_pageload (0x6) the 8/16-bit risc cpu specific public jtag instruction to directly load the flash data page via the jtag port. an 8-bit flash data byte register is selected as the data register. this is physi- cally the 8 lsbs of the programming command register. the active states are the following: ? shift-dr: the flash data byte register is shifted by the tck input. ? update-dr: the content of the flash data byte register is copied into a temporary register. a write sequence is initiated that within 11 tck cycles loads the content of the temporary register into the flash page buffer. the 8/16-bit risc cpu automatically alternates between writing the low and the high byte for each new update-dr state, starting with the low byte for the first update-dr encountered after entering the prog_pageload command. the program counter is pre-incremented before writing the low byte, except for the first written byte. this ensures that the first data is written to the address set up by prog_commands, and loading the last location in the page buffer does not make the program counter increment into the next page. 29.8.6 prog_pageread (0x7) the 8/16-bit risc cpu specific public jtag instruction to directly capture the flash content via the jtag port. an 8-bit flash data byte register is selected as the data register. this is physi- cally the 8 lsbs of the programming command register. the active states are the following:
at90scr100/116/132 402 tpr0327b ? vic ? 16fev11 ? capture-dr: the content of the selected flash byte is captured into the flash data byte register. the 8/16-bit risc cpu automatically alternates between reading the low and the high byte for each new capture-dr state, starting with the low byte for the first capture-dr encountered after entering the prog_pageread command. the program counter is post- incremented after reading each high byte, including the first read byte. this ensures that the first data is captured from the first address set up by prog_commands, and reading the last location in the page makes the program counter increment into the next page. ? shift-dr: the flash data byte register is shifted by the tck input. 29.8.7 data registers the data registers are selected by the jtag instruction registers described in section ?pro- gramming specific jtag instructions? on page 400 . the data registers relevant for programming operations are: ? reset register ? programming enable register ? programming command register ? flash data byte register 29.8.8 reset register the reset register is a test data register used to reset the part during programming. it is required to reset the part before entering programming mode. a high value in the reset register corresponds to pulling the external reset low. the part is reset as long as there is a high value present in the reset register. the part will remain reset for a reset time-out period (refer to table 7-3, ?start-up times for the low power crystal oscillator clock selection,? on page 45 ) after releasing the reset register. the output from this data reg- ister is not latched, so the reset will take place immediately, as shown in figure 27-2 on page 369 . 29.8.9 programming enable register the programming enable register is a 16-bit register. the contents of this register is compared to the programming enable signature, binary code 0b1010_0011_0111_0000. when the con- tents of the register is equal to the programming enable signature, programming via the jtag port is enabled. the register is reset to 0 on power-on reset, and should always be reset when leaving programming mode. figure 29-5. programming enable register tdi tdo d a t a = dq clockdr & prog_enable programming enable 0xa370
403 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 29.8.10 programming command register the programming command register is a 15-bit register. this register is used to serially shift in programming commands, and to serially shift out the result of the previous command, if any. the jtag programming instruction set is shown in table 29-12 . the state sequence when shifting in the programming commands is illustrated in figure 29-7 . figure 29-6. programming command register tdi tdo s t r o b e s a d d r e s s / d a t a flash eeprom fuses lock bits
at90scr100/116/132 404 tpr0327b ? vic ? 16fev11 table 29-12. jtag programming instruction set a = address high bits, b = address low bits, c = address extended bits, h = 0 - low byte, 1 - high byte, o = data out, i = data in, x = don?t care instruction tdi sequence tdo sequence notes 1a. chip erase 0100011_10000000 0110001_10000000 0110011_10000000 0110011_10000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx 1b. poll for chip erase complete 0110011_10000000 xxxxxox_xxxxxxxx (1) 2a. enter flash write 0100011_00010000 xxxxxxx_xxxxxxxx 2b. load address extended high byte 0001011_cccccccc xxxxxxx_xxxxxxxx (2) 2c. load address high byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 2d. load address low byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 2e. load data low byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx 2f. load data high byte 0010111_iiiiiiii xxxxxxx_xxxxxxxx 2g. latch data 0110111_00000000 1110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 2h. write flash page 0110111_00000000 0110101_00000000 0110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 2i. poll for page write complete 0110111_00000000 xxxxxox_xxxxxxxx (1) 3a. enter flash read 0100011_00000010 xxxxxxx_xxxxxxxx 3b. load address extended high byte 0001011_cccccccc xxxxxxx_xxxxxxxx (2) 3c. load address high byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 3d. load address low byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 3e. read data low and high byte 0110010_00000000 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo xxxxxxx_oooooooo low byte high byte 4a. enter eeprom write 0100011_00010001 xxxxxxx_xxxxxxxx 4b. load address high byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx (2) 4c. load address low byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 4d. load data byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx 4e. latch data 0110111_00000000 1110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 4f. write eeprom page 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 4g. poll for page write complete 0110011_00000000 xxxxxox_xxxxxxxx (1)
405 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 5a. enter eeprom read 0100011_00000011 xxxxxxx_xxxxxxxx 5b. load address high byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx (2) 5c. load address low byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 5d. read data byte 0110011_bbbbbbbb 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 6a. enter fuse write 0100011_01000000 xxxxxxx_xxxxxxxx 6b. load data low byte (4) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (5) 6c. write fuse extended byte 0111011_00000000 0111001_00000000 0111011_00000000 0111011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 6d. poll for fuse write complete 0110111_00000000 xxxxxox_xxxxxxxx (1) 6e. load data low byte (6) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (5) 6f. write fuse high byte 0110111_00000000 0110101_00000000 0110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 6g. poll for fuse write complete 0110111_00000000 xxxxxox_xxxxxxxx (1) 6h. load data low byte (6) 0010011_iiiiiiii xxxxxxx_xxxxxxxx (5) 6i. write fuse low byte 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 6j. poll for fuse write complete 0110011_00000000 xxxxxox_xxxxxxxx (1) 7a. enter lock bit write 0100011_00100000 xxxxxxx_xxxxxxxx 7b. load data byte (7) 0010011_11iiiiii xxxxxxx_xxxxxxxx (8) 7c. write lock bits 0110011_00000000 0110001_00000000 0110011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 7d. poll for lock bit write complete 0110011_00000000 xxxxxox_xxxxxxxx (1) 8a. enter fuse/lock bit read 0100011_00000100 xxxxxxx_xxxxxxxx 8b. read extended fuse byte (4) 0111010_00000000 0111011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 8c. read fuse high byte (6) 0111110_00000000 0111111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 8d. read fuse low byte (9) 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo table 29-12. jtag programming instruction (continued) set (continued) a = address high bits, b = address low bits, c = address extended bits, h = 0 - low byte, 1 - high byte, o = data out, i = data in, x = don?t care instruction tdi sequence tdo sequence notes
at90scr100/116/132 406 tpr0327b ? vic ? 16fev11 notes: 1. repeat until o = ?1?. 2. address bits exceeding pcmsb and eeamsb ( table 29-7 and table 29-8 ) are don?t care 3. this command sequence is not required if the seven msb are correctly set by the previous command sequence (which is normally the case). 4. the bit mapping for fuses extended byte is listed in table 29-3 on page 393 5. set bits to ?0? to program the corresponding fuse, ?1? to unprogram the fuse. 6. the bit mapping for fuses high byte is listed in table 29-4 on page 393 7. the bit mapping for lock bits byte is listed in table 29-1 on page 391 8. set bits to ?0? to program the corresponding lock bit, ?1? to leave the lock bit unchanged. 9. the bit mapping for fuses low byte is listed in table 29-5 on page 394 10. ?0? = programmed, ?1? = unprogrammed. 8e. read lock bits (7) 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxoooooo (10) 8f. read fuses and lock bits 0111010_00000000 0111110_00000000 0110010_00000000 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo xxxxxxx_oooooooo xxxxxxx_oooooooo xxxxxxx_oooooooo (10) fuse ext. byte fuse high byte fuse low byte lock bits 9a. enter signature byte read 0100011_00001000 xxxxxxx_xxxxxxxx 9b. load address byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 9c. read signature byte 0110010_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 10a. enter calibration byte read 0100011_00001000 xxxxxxx_xxxxxxxx 10b. load address byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 10c. read calibration byte 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 11a. load no operation command 0100011_00000000 0110011_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx table 29-12. jtag programming instruction (continued) set (continued) a = address high bits, b = address low bits, c = address extended bits, h = 0 - low byte, 1 - high byte, o = data out, i = data in, x = don?t care instruction tdi sequence tdo sequence notes note note all tdi and tdo sequences are represented by binary digits (0b...).
407 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 figure 29-7. state machine sequence to change/read the data word 29.8.11 flash data byte register the flash data byte register provides an ef ficient way to load the entire flash page buffer before executing page write, or to read out/verify the content of the flash. a state machine sets up the control signals to the flash and senses t he strobe signals from the flash, thus only the data words need to be shifted in/out. the flash data byte register actually consists of the 8-bit scan chain and a 8-bit temporary reg- ister. during page load, the update-dr state copies the content of the scan chain over to the temporary register and initiates a write sequence that within 11 tck cycles loads the content of the temporary register into the flash page buffer. the 8/16-bit risc cpu automatically alter- nates between writing the low and the high byte for each new update-dr state, starting with the low byte for the first update-dr encountered after entering the prog_pageload command. the program counter is pre-incremented before writing the low byte, except for the first written byte. this ensures that the first data is written to the address set up by prog_commands, and loading the last location in the page buffer does not make the program counter increment into the next page. during page read, the content of the selected flash byte is captured into the flash data byte register during the capture-dr state. the 8/16-bit risc cpu automatically alternates between reading the low and the high byte for each new capture-dr state, starting with the low byte for test-logic-reset run-test/idle shift-dr exit1-dr pause-dr exit2-dr update-dr select-ir scan capture-ir shift-ir exit1-ir pause-ir exit2-ir update-ir select-dr scan capture-dr 0 1 0 11 1 00 00 11 1 0 1 1 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1
at90scr100/116/132 408 tpr0327b ? vic ? 16fev11 the first capture-dr encountered after entering the prog_pageread command. the pro- gram counter is post-incremented after reading each high byte, including the first read byte. this ensures that the first data is captured from the first address set up by prog_commands, and reading the last location in the page makes the program counter increment into the next page. figure 29-8. flash data byte register the state machine controlling the flash data byte register is clocked by tck. during normal operation in which eight bits are shifted for each flash byte, the clock cycles needed to navigate through the tap controller automatically feeds the state machine for the flash data byte regis- ter with sufficient number of clock pulses to complete its operation transparently for the user. however, if too few bits are shifted between each update-dr state during page load, the tap controller should stay in the run-test/idle stat e for some tck cycles to ensure that there are at least 11 tck cycles between each update-dr state. 29.8.12 programming algorithm all references below of type ?1a?, ?1b?, and so on, refer to table 29-12 . 29.8.13 entering programming mode 1. enter jtag instruction avr_reset and shift 1 in the reset register. 2. enter instruction prog_enable and shift 0b1010_0011_0111_0000 in the program- ming enable register. 29.8.14 leaving programming mode 1. enter jtag instruction prog_commands. 2. disable all programming instructions by using no operation instruction 11a. 3. enter instruction prog_enable and shift 0b0000_0000_0000_0000 in the program- ming enable register. 4. enter jtag instruction avr_reset and shift 0 in the reset register. tdi tdo d a t a flash eeprom fuses lock bits strobes address state machine
409 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 29.8.15 performing chip erase 1. enter jtag instruction prog_commands. 2. start chip erase using programming instruction 1a. 3. poll for chip erase complete using programming instruction 1b. 29.8.16 programming the flash before programming the flash a chip erase must be performed. see ?performing chip erase? on page 409. 1. enter jtag instruction prog_commands. 2. enable flash write using programming instruction 2a. 3. load address extended high byte using programming instruction 2b. 4. load address high byte using programming instruction 2c. 5. load address low byte using programming instruction 2d. 6. load data using programming instructions 2e, 2f and 2g. 7. repeat steps 5 and 6 for all instruction words in the page. 8. write the page using programming instruction 2h. 9. poll for flash write complete using programming instruction 2i. 10. repeat steps 3 to 9 until all data have been programmed. a more efficient data transfer can be achieved using the prog_pageload instruction: 1. enter jtag instruction prog_commands. 2. enable flash write using programming instruction 2a. 3. load the page address using programming instructions 2b, 2c and 2d. pcword (refer to table 29-7 on page 395 ) is used to address within one page and must be written as 0. 4. enter jtag instruction prog_pageload. 5. load the entire page by shifting in all instruction words in the page byte-by-byte, start- ing with the lsb of the first instruction in the page and ending with the msb of the last instruction in the page. use update-dr to copy the contents of the flash data byte register into the flash page location and to auto-increment the program counter before each new word. 6. enter jtag instruction prog_commands. 7. write the page using programming instruction 2h. 8. poll for flash write complete using programming instruction 2i. 9. repeat steps 3 to 8 until all data have been programmed. 29.8.17 reading the flash 1. enter jtag instruction prog_commands. 2. enable flash read using programming instruction 3a. 3. load address using programming instructions 3b, 3c and 3d. 4. read data using programming instruction 3e. 5. repeat steps 3 and 4 until all data have been read. a more efficient data transfer can be achieved using the prog_pageread instruction: 1. enter jtag instruction prog_commands. 2. enable flash read using programming instruction 3a.
at90scr100/116/132 410 tpr0327b ? vic ? 16fev11 3. load the page address using programming instructions 3b, 3c and 3d. pcword (refer to table 29-7 on page 395 ) is used to address within one page and must be written as 0. 4. enter jtag instruction prog_pageread. 5. read the entire page (or flash) by shifting out all instruction words in the page (or flash), starting with the lsb of the first instruction in the page (flash) and ending with the msb of the last instruction in the page (flash). the capture-dr state both captures the data from the flash, and also auto-increments the program counter after each word is read. note that capture-dr comes before the shift-dr state. hence, the first byte which is shifted out contains valid data. 6. enter jtag instruction prog_commands. 7. repeat steps 3 to 6 until all data have been read. 29.8.18 programming the eeprom before programming the eeprom a chip erase must be performed. see ?performing chip erase? on page 409. 1. enter jtag instruction prog_commands. 2. enable eeprom write using programming instruction 4a. 3. load address high byte using programming instruction 4b. 4. load address low byte using programming instruction 4c. 5. load data using programming instructions 4d and 4e. 6. repeat steps 4 and 5 for all data bytes in the page. 7. write the data using programming instruction 4f. 8. poll for eeprom write complete using programming instruction 4g. 9. repeat steps 3 to 8 until all data have been programmed. note that the prog_pageload instruction can not be used when programming the eeprom. 29.8.19 reading the eeprom 1. enter jtag instruction prog_commands. 2. enable eeprom read using programming instruction 5a. 3. load address using programming instructions 5b and 5c. 4. read data using programming instruction 5d. 5. repeat steps 3 and 4 until all data have been read. note that the prog_pageread instruction can not be used when reading the eeprom. 29.8.20 programming the fuses 1. enter jtag instruction prog_commands. 2. enable fuse write using programming instruction 6a. 3. load data high byte using programming instructions 6b. a bit value of ?0? will program the corresponding fuse, a ?1? will unprogram the fuse. 4. write fuse high byte using programming instruction 6c. 5. poll for fuse write complete using programming instruction 6d. 6. load data low byte using programming instructions 6e. a ?0? will program the fuse, a ?1? will unprogram the fuse. 7. write fuse low byte using programming instruction 6f. 8. poll for fuse write complete using programming instruction 6g.
411 tpr0327b ? vic ? 16fev11 29. memory programming at90scr100/116/132 29.8.21 programming the lock bits 1. enter jtag instruction prog_commands. 2. enable lock bit write using programming instruction 7a. 3. load data using programming instructions 7b. a bit value of ?0? will program the corre- sponding lock bit, a ?1? will leave the lock bit unchanged. 4. write lock bits using programming instruction 7c. 5. poll for lock bit write complete using programming instruction 7d. 29.8.22 reading the fuses and lock bits 1. enter jtag instruction prog_commands. 2. enable fuse/lock bit read using programming instruction 8a. 3. to read all fuses and lock bits, use programming instruction 8e. to only read fuse high byte, use programming instruction 8b. to only read fuse low byte, use programming instruction 8c. to only read lock bits, use programming instruction 8d. 29.8.23 reading the signature bytes 1. enter jtag instruction prog_commands. 2. enable signature byte read using programming instruction 9a. 3. load address 0x00 using programming instruction 9b. 4. read first signature byte using programming instruction 9c. 5. repeat steps 3 and 4 with address 0x01 and address 0x02 to read the second and third signature bytes, respectively. 29.8.24 reading the calibration byte 1. enter jtag instruction prog_commands. 2. enable calibration byte read using programming instruction 10a. 3. load address 0x00 using programming instruction 10b. 4. read the calibration byte using programming instruction 10c.
at90scr100/116/132 412 tpr0327b ? vic ? 16fev11
413 tpr0327b ? vic ? 16fev11 30. application information at90scr100/116/132 30. application information 30.1 ordering information note: 1. for differences between different configurations please see ?pin list configuration? on page 15 . 2. standard spi present see ?pin list configuration? on page 15 for complete configuration. 3. high-speed spi present see ?pin list configuration? on page 15 for complete configuration. table 30-1. ordering information (1) part number voltage range (v) temperature range package packing at90scr100lsd-z1t (2) 2.4-5.5 industrial & green qfn32 tray at90scr100lsd-z1r (2) 2.4-5.5 industrial & green qfn32 reel at90scr100lhs-z1t (3) 2.4-5.5 industrial & green qfn32 tray AT90SCR100LHS-Z1R (3) 2.4-5.5 industrial & green qfn32 reel at90scr100h-alt 2.4-5.5 industrial & green lqfp64 tray at90scr100h-alr 2.4-5.5 industrial & green lqfp64 reel at90scr100h-z1t 2.4-5.5 industrial & green qfn64 tray at90scr100h-z1r 2.4-5.5 industrial & green qfp64 reel note note on at90scr100lsd and at90scr100lhs, the jtag is not accessible. on at90scr100lhs, the isp though spi is neither accessible. caution ! on all packages, the e-pad must be connected to ground.
at90scr100/116/132 414 tpr0327b ? vic ? 16fev11 30.2 typical application table 30-2. external components, bill of materials vss c1 3.3v c2 r1 r2 c3 c4 vss2 vss3 avss cvcc cvsense cc4 cc8 cio cvss rst d+ d- d+ d- reset : as dcdc generates noise, we encourage the use of another supply power than global vcc, if possible. vcc4 vcc3 vcc2 vcc1 vdcdc dvcc xtal1 xtal2 ucap vcc at90scr100 host c5 c6 q1 3.3v r3 r4 r5 rs rled dled rtc1 rtc2 led0 li lo c7 c8 l1 q2 c9 card vcc card c4/d+ card c8/d- card io (1) (1) 3.3v reference description value comment r1, r2 r3, r4 usb pad serial resistor 22 +/-10% - r5 cio pull-up resistor 10k +/-10% (optional) can be required for high speed communication rs dcdc sense resistor 200m +/-2% 125mw current sensing: overcurrent detection c1 power supply decoupling capacitor 4.7 f +/-10% maximum application capacitance allowed by usb standard is 10 f c2 power supply filter capacitor 100nf - c3 internal core regulator decoupling capacitor 2.2 f +/-10% used for internal regulator stability c4 internal usb regulator decoupling capacitor 2.2 f +/-10% used for internal regulator stability c5, c6 pll filter capacitors 10pf +/-10% - c7, c8 rtc filter capacitors 22pf +/-10% only if real time counter is used. c9 dcdc decoupling capacitor 10 f +/-10% esr=100m tantalum capacitor is needed recommended: avx: tpse106-035- 200
415 tpr0327b ? vic ? 16fev11 30. application information at90scr100/116/132 note: 1. this is a representation of the resistances 30.2.1 recommendations 1. in order to reduce the board parasitics , the external components for dcdc converter should be as close as possible to the chip pins (ideally solded directly on the pins). 2. in order to have a correct current limitation, the board parasitic resistances must be taken into account in the choice of the rs value (e.g., if each metal line connecting rs to the chip adds a 10 m resistance, the correct rs value should be 200-2x10=180m ) 3. cvcc and cvss lines must have very low resistance (short and wide metal line). 4. r1, r2, r3 and r4 must be placed as close as possible to the chip pins. 5. connect e-pad to ground. if possible connect it to ground plane l1 dcdc inductance 6.8 h esr=20.2m recommended: gowanda: smp3316lp-681m q1 crystal 8.0 mhz q2 real time crystal 3.768 mhz only if real time counter is used rled/dled led mechanism -- depends on the configuration of the led controller reference description value comment vcc die r pcb rs r wires r pcb depends of the wire?s section and length. please note that this wire must be designed to support 200ma and be the thinest possible. rwire is given in ?smart card interface characteristics? on page 428 . rs =200mohms-r pcb -r wires
at90scr100/116/132 416 tpr0327b ? vic ? 16fev11 30.3 pinout 30.3.1 at90scr100lsd - qfn32 => standard spi qfn32 9 usb_d+ ucap pc2 (led0) pb6 (miso) pb5(mosi) pb7 (sck) vcc2 pb4 (ss) 10 11 12 13 14 15 16 2 3 4 5 xtal2 6 cc4/host_d+ 7 cc8/host_d- 8 usb_d- 24 li 25 cvss 26 cvsense 27 vdcdc 28 lo 29 30 pd0 (rxd) 31 pd1 (txd) 32 vss1 1 23 cvcc 22 avss 21 cclk 20 crst 19 cio 18 cpres 17 vss2 vcc1 dvcc vss3 xtal1 reset
417 tpr0327b ? vic ? 16fev11 30. application information at90scr100/116/132 30.3.2 at90scr100lhs - qfn32 => high-speed spi qfn32 9 usb_d+ ucap pc2 (led0) pd7 (hs-miso) pd6(hs-mosi) pd5 (hs-sck) vcc2 pd4 (hs-ss) 10 11 12 13 14 15 16 2 3 4 5 xtal2 6 cc4/host_d+ 7 cc8/host_d- 8 usb_d- 24 li 25 cvss 26 cvsense 27 vdcdc 28 lo 29 30 pd0 (rxd) 31 pd1 (txd) 32 vss1 1 23 cvcc 22 avss 21 cclk 20 crst 19 cio 18 cpres 17 vss2 vcc1 dvcc vss3 xtal1 reset
at90scr100/116/132 418 tpr0327b ? vic ? 16fev11 30.3.3 at90scr100h - qfn64 & lqfp64 qfn64 1 pa1 (kbin1) 2 pa2 (kbin2) 3 pa3 (kbin3) 4 5 6 7 8 9 10 11 12 13 14 15 16 pe5 (kbo5) vcc1 vcc2 dvcc rtc1 (tosc1) rtc2 (tosc2) xtal1 xtal2 cc4/host_d+ cc8/host_d- usb_d- usb_d+ 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 li cvcc cclk crst cio cpres vcc5 pa7 (kbin7) pa6 (kbin6) pd2 (int0) pd3 (int1) pb0 (int2) pd4 (hs-ss) pb3 (pwm) pb4 (ss) e-pad, underneath package must be connected to ground nc: not connected (pin16, 32) 32 31 30 29 28 27 26 25 24 23 21 22 20 19 18 17 nc vcc4 pd5 (hs-sck) pb7 (sck) pd6 (hs-mosi) pb5 (mosi) pe7 (kbo7) pe6 (kbo6) pd7 (hs-miso) pb6 (miso) pc5 (led3) vcc3 pc4 (led2) pc3 (led1) pc2 (led0) ucap 49 50 51 52 53 54 55 56 57 58 60 59 61 62 63 64 pe4 (kbo4) pb1 (int3) pe3 (kbo3) pa0 (kbin0) pe2 (kbo2) pe1 (kbo1) pe0 (kbo0) pa5 (kbin5) pa4 (kbin4) pb2 pd1 (txd) pd0 (rxd) pc1 (sda) pc0 (scl) lo vdcdc cvsense reset
419 tpr0327b ? vic ? 16fev11 30. application information at90scr100/116/132 30.4 mechanical information 30.4.1 qfn32 d e e b a3 0.10 a2 a1 a d2 e2 0.05 c l 1 2 3 1 2 3 pin 1 id pitch #1 notch (0.20 r) common dimensions (unit of measure = mm) symbol min nom max a 0.90 a1 0.05 a2 0.65 0.70 a3 0.20 ref b 0.18 0.25 0.30 d d2 3.40 3.50 3.80 5.00 bsc 5.00 bsc e e2 3.40 3.50 3.60 e 0.50 bsc l 0.40 k 0.35 C 0.45 0.35 C C C C C C k 0.45 k top view bottom side note: jedec standard mo-220, fig. 2 (anvil singulation), vhhd-2 1. all dimensions are in millimeters. 2. die thickness allowable is 0.305mm maximum. 3. dimensioning & tolerances conform to asme y14.5m. 1994. 4. the pin #1 identifier must be placed on the top surface of the package by using identification mark or other feature of package body. 5. exact shape and size of this feature is optimal. 6. package warpage max 0.08mm. 7. applied for exposed pad and terminals. exclude embedding part of exposed pard from measuring 8. applied only to terminals
at90scr100/116/132 420 tpr0327b ? vic ? 16fev11 30.4.2 qfn 64 e e b d2 e2 l 1 2 3 a2 a1 a 0.05 c pin 1 id top view bottom side pitch #1 notch (0.20 r) d c common dimensions (unit of measure = mm) note: compliant jedec standard mo-220 variation vmmd-3 symbol a a1 a2 d/e e l b d2/e2 0.90 0.05 0.70 0.55 0.28 7.25 C 0 C 0.30 0.23 6.95 0.50 bsc C C C 9.00 bsc 0.40 0.25 C min nom max
421 tpr0327b ? vic ? 16fev11 30. application information at90scr100/116/132 30.4.3 lqfp64 pin 1 identifier 0~7 pin 1 l l1 c a1 a2 a d1 d2 d e e1 e2 e b notes: 1. this drawing is for general information only. refer to jedec drawing ms-026 for additional information. common dimensions (unit of measure = symbol min nom max a C C 1.60 a1 0.05 C 0.15 a2 1.35 1.40 1.45 d 12.00 bsc d1 10.00 bsc d2 7.50 e 12.00 bsc e1 10.00 bsc e2 7.50 b 0.17 0.20 0.27 c 0.09 C 0.20 l 0.45 0.60 0.75 l1 1.00 ref e 0.50 bsc 64-lead
at90scr100/116/132 422 tpr0327b ? vic ? 16fev11
423 tpr0327b ? vic ? 16fev11 31. electrical characteristics at90scr100/116/132 31. electrical characteristics 31.1 scope the at90scr100/116/132 application can make the use of the internal dc/dc converter or not. please pay attention to the configuration of the at90scr100/116/132 before reading the table, to match your particular needs. at90scr100/116/132 without active dc/dc: vcc range: 2.4v - 5.5v at90scr100/116/132 with active dc/dc: vcc range: 2.7v - 5.5v 31.2 dc characteristics notes: 1. all dc characteristics contained in this datasheet are based on characterization of other 8/16-bit risc cpu microcon- trollers and peripherals. these values are preliminary values representing design targets, and will be updated after characterization of silicon. absolute maximum ratings* operating temperature.................................... -40 c to +85 c *notice: stresses beyond those listed under ?absoute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. exposure to absolute maximum rating con- ditions for extended periods may affect device reliability. storage temperature ..................................... -65c to +150c voltage on any pin with respect to ground..-0.5v to v cc +0.5v maximum operating voltage ............................................ 6.0v dc current v cc and gnd pins.........................................tbd t a = -40 c to 85 c, v cc = 2.4v to 5.5v (unless otherwise noted) symbol parameter condition min. (1) typ. max. (1) units v il (2) input low voltage v cc = 2.4v - 5.5v 0.8 (3) v v ih (2) input high voltage v cc = 2.4v - 5.5v 2.0 (4) v v ol (2) output low voltage, v cc = 2.4v - 5.5v 0.4 v v oh (2) output high voltage, v cc = 2.4v - 5.5v 0.8vcc v i il (2) input leakage current i/o pin v cc = 5.5v, pin low (absolute value) 1 a i ih (2) input leakage current i/o pin v cc = 5.5v, pin high (absolute value) 1 a r rst reset pull-up resistor 75 135 k r pu i/o pin pull-up resistor 8 25 k i cc power supply current (5) active 8mhz, v cc = 5v tbd ma idle 8mhz, v cc = 5v tbd ma power-down mode (6) v cc = 5v 200 (7) a
at90scr100/116/132 424 tpr0327b ? vic ? 16fev11 2. these parameters are only for standard i/os. these only include: keyboard inputs, external interrupts, standard serial peripheral interface (spi), high-speed serial peripheral in terface (hsspi), jtag/led ports (driving only 2 or 4ma), 2- wire interface, timers i/os, usart. 3. "max" means the highest value where the pin is guaranteed to be read as low 4. "min" means the lowest value where the pin is guaranteed to be read as high 5. values with ?prr0 ? power reduction register 0? and ?prr1 ? power reduction register 1? disabled (0x00). 6. power-down values includes input in tri-state mode 7. for usb suspend power-down current measure, you should add 200 a generated by the different resistors on usb d+/d- lines. 31.3 ports notes: 1. all dc characteristics contained in this datasheet are based on characterization of other 8/16-bit risc cpu microcon- trollers and peripherals. these values are preliminary values representing design targets, and will be updated after characterization of silicon. 2. standard ports 3. led ports driving 4 ma 4. led ports driving 2 ma and keyboard output 31.4 clocks 31.4.1 xtal1 : external clock in tbc/tbd this clock relates to core and system clock. see ?clock sources? on page 43. 31.5 communication interfaces 31.5.1 2-wire serial interface characteristics table 31-2 describes the requirements for devices connected to the 2-wire serial bus. the at90scr100/116/132 2-wire serial interface meets or exceeds these requirements under the noted conditions. symbol parameter condition min. (1) typ. max. (1) units v oh output high voltage v cc = 2.4v - 5.5v i 0l (2) = 8 ma i 0l (3) = 4 ma i 0l (4) = 2 ma 0,4 v table 31-1. xtal1 = xin clock electrical characteristics symbol parameter min. typ. max. units 1/t cpxin xin clock frequency 8 mhz t chxin xin clock high half-period tbd t clcx xin clock low half-period tbd c in xin input capacitance 10 pf
425 tpr0327b ? vic ? 16fev11 31. electrical characteristics at90scr100/116/132 timing symbols refer to figure 31-1 . notes: 1. in at90scr100/116/132, this parameter is characterized and not 100% tested. 2. required only for f scl > 100 khz. 3. cb = capacitance of one bus line in pf. 4. f ck = cpu clock frequency 5. this requirement applies to all at90scr100/116/132 two-wire serial interface operation. other devices connected to the two-wire serial bus need only obey the general f scl requirement. 6. the actual low period generated by the at90scr100/116/132 two-wire serial interface is (1/f scl - 2/f ck ), thus f ck must be greater than 6 mhz for the low time requirement to be strictly met at f scl = 100 khz. 7. the actual low period generated by the at90scr100/116/132 two-wire serial interface is (1/f scl - 2/f ck ), thus the low time requirement will not be strictly met for f scl > 308 khz when f ck = 8 mhz. still, at90scr100/116/132 devices con- nected to the bus may communicate at full speed (400 khz) with other at90scr100/116/132 devices, as well as any other device with a proper t low acceptance margin. 8. this parameter is theorical and is not part of the production test flow. it represents a some idea of the size of the param- eter, but the exact value is not guaranteed. table 31-2. 2-wire serial bus requirements symbol parameter condition min max units v il input low-voltage -0.5 0.3 v cc v v ih input high-voltage 0.6 v cc v cc + 0.5 v v ol (1) output low-voltage 3 ma sink current 0 0.4 v t r (1)(8) rise time for both sda and scl 20 + 0.1c b (2)(3) 300 ns t of (1)(8) output fall time from v ihmin to v ilmax 10 pf < c b < 400 pf (3) 20 + 0.1c b (2)(3) 250 ns t sp (1)(8) spikes suppressed by input filter 0 50 (2) ns c i (1)(8) capacitance for each i/o pin ? 10 pf f scl scl clock frequency f ck (4) > max(16f scl , 250khz) (5) 0400khz t hd;sta hold time (repeated) start condition f scl 100 khz 4.0 ? s f scl > 100 khz 0.6 ? s t low low period of the scl clock f scl 100 khz (6) 4.7 ? s f scl > 100 khz (7) 1.3 ? s t high high period of the scl clock f scl 100 khz 4.0 ? s f scl > 100 khz 0.6 ? s t su;sta set-up time for a repeated start condition f scl 100 khz 4.7 ? s f scl > 100 khz 0.6 ? s t hd;dat data hold time f scl 100 khz 0 3.45 s f scl > 100 khz 0 0.9 s t su;dat data setup time f scl 100 khz 250 ? ns f scl > 100 khz 100 ? ns t su;sto setup time for stop condition f scl 100 khz 4.0 ? s f scl > 100 khz 0.6 ? s t buf bus free time between a stop and start condition f scl 100 khz 4.7 ? s f scl > 100 khz 1.3 ? s
at90scr100/116/132 426 tpr0327b ? vic ? 16fev11 figure 31-1. 2-wire serial bus timing 31.5.2 spi timing characteristics see figure 31-2 and figure 31-3 for details. notes: 1. in spi programming mode the minimum sck high/low period is: - 2 t clcl for f ck < 12 mhz - 3 t clcl for f ck > 12 mhz 2. these values are for information only. they are not tested to production test flow. they are deduced from characteriza- tion session. t su;sta t low t high t low t of t hd;sta t hd;dat t su;dat t su;sto t buf scl sda t r table 31-3. spi timing parameters (2) description mode min typ max 1 sck period master see table 20-4 ns 2 sck high/low master 50% duty cycle 3 rise/fall time master 3.6 4 setup master 10 5holdmaster 10 6 out to sck master 0.5 ? t sck 7 sck to out master 10 8 sck to out high master 10 9ss low to out slave 15 10 sck period slave 4 ? t ck 11 sck high/low (1) slave 2 ? t ck 12 rise/fall time slave 1600 13 setup slave 10 14 hold slave t ck 15 sck to out slave 15 16 sck to ss high slave 20 17 ss high to tri-state slave 10 18 ss low to sck slave 20
427 tpr0327b ? vic ? 16fev11 31. electrical characteristics at90scr100/116/132 figure 31-2. spi interface timing requirements (master mode) figure 31-3. spi interface timing requirements (slave mode) mo si (data output) sck (cpol = 1) mi so (data input) sck (cpol = 0) ss msb lsb lsb msb ... ... 61 22 3 45 8 7 mi so (data output) sck (cpol = 1) mo si (data input) sck (cpol = 0) ss msb lsb lsb msb ... ... 10 11 11 12 13 14 17 15 9 x 16
at90scr100/116/132 428 tpr0327b ? vic ? 16fev11 31.6 usb interface characteristics 31.7 smart card interface characteristics table 31-4. usb electrical parameters symbol parameter condition min. typ. max. units 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 0.2 v v cm differential common mode range 0.8 2.5 v v ol1 static output low 0.3 v v oh1 static output high 2.8 3.6 v c in input capacitance 20 pf t r rise time cout = 50 pf 4 20 ns t f fall time cout = 50 pf 4 20 ns t rfm rise / fall time matching (t r /t r )90110% z drv driver output resistance steady state drive 28 44 ohm t drate full speed data rate average bit rate 11.97 12.03 mb/s t frame frame interval 0.9995 1.0005 ms caution ! vcc must be higher than 3.2v to supply power for usb interface and use correctly this macro. table 31-5. smart card class a, 5v (cvcc) symbol parameter min typ max unit test conditions cvcc smart card voltage with vcc = 2.7v to 2.85v with vcc > 2.85v 4.6 4.6 5 5 5.4 5.4 v load = 50ma load = 60ma spikes on cvcc tbd v vcardok vcardok level threshold 4.2 4.6 v t vhl cvcc valid to 0.4v 1 ms t vlh cvcc 0 to valid 250 s r bw resistance of the bonding wires tbd mohms
429 tpr0327b ? vic ? 16fev11 31. electrical characteristics at90scr100/116/132 table 31-6. smart card class b, 3v (cvcc) symbol parameter min typ max unit test conditions cvcc smart card voltage with vcc = 2.7v to 2.85v with vcc > 2.85v 2.76 2.76 3 3 3.24 3.24 v load = 50ma load = 60ma spikes on cvcc tbd v vcardok vcardok level threshold 2.5 2.76 v t vhl cvcc valid to 0.4v 1 ms t vlh cvcc 0 to valid 250 s r bw resistance of the bonding wires tbd mohms table 31-7. smart card c, 1.8v (cvcc) symbol parameter min typ max unit test conditions cvcc smart card voltage 1.66 1.8 1.944 v load = 35ma spikes on cvcc tbd v vcardok vcardok level threshold 1.5 1.66 v t vhl cvcc valid to 0.4v 1 ms t vlh cvcc 0 to valid 250 s r bw resistance of the bonding wires tbd mohms table 31-8. smart card card presence (cpres) symbol parameter min typ max unit test conditions i ol1 cpres weak pull-up output current vcc = 3v 25 35 a short to vss pullup = 1: internal pull-up active
at90scr100/116/132 430 tpr0327b ? vic ? 16fev11
431 tpr0327b ? vic ? 16fev11 32. register summary at90scr100/116/132 32. register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page (0xff) scicr reset carddet vca rd1 vcard0 uart wten crep conv 203 (0xfe) sccon clk - cardc8 cardc4 cardio cardclk cardrst cardvcc 205 (0xfd) scisr sctbe cardin - vcardok scwto sctc scrc scpe 206 (0xfc) sciir sctbi - - vcarderr scwti scti scri scpi 208 (0xfb) scier esctbi cardine - ivcarder escwti escti escri escpi 209 (0xfa) scsr -bgten - crepsel cpresres - - - 210 (0xf9) scibuf scibufd [7..0] 210 (0xf8) scetuh comp - - - - etu [10:8] 211 (0xf7) scetul etu [7:0] 211 (0xf6) scgth - - - - - - -gt8 212 (0xf5) scgtl gt [7:0] 212 (0xf4) scwt3 wt31 wt30 wt29 wt28 wt27 wt26 wt25 wt24 212 (0xf3) scwt2 wt23 wt22 wt21 wt20 wt19 wt18 wt17 wt16 212 (0xf2) scwt1 wt15 wt14 wt13 wt12 wt11 wt10 wt9 wt8 212 (0xf1) scwt0 wt7 wt6 wt5 wt4 wt3 wt2 wt1 wt0 212 (0xf0) sciclk - - sciclk5 sciclk4 sciclk3 sciclk2 sciclk1 sciclk0 213 (0xef) dccr dcon dcrdy dcbusy - - - - - 217 (0xee) reserved - - - - - - - - (0xed) usbdmab - usbdmab [6..0] 185 (0xec) usbdmadh - - usbdmad [13..8] 184 (0xeb) usbdmadl usbdmad [7..0] 184 (0xea) usbdmacs - eps2 eps1 eps0 - dmaerr dmair dmar 182 (0xe9) usbfnh - - - fnend fnerr fn10 fn9 fn8 181 (0xe8) usbfnl fn7 fn6 fn5 fn4 fn3 fn2 fn1 fn0 181 (0xe7) usbfa - fadd6 fadd5 fadd4 fadd3 fadd2 fadd1 fadd0 180 (0xe6) usbgs - - - - rsmon rmwue fcf faf 179 (0xe5) usbrste rst rste6 rste5 rste4 rste3 rste2 rste1 rste0 179 (0xe4) usbeim ep7im ep7im ep5im ep4im ep3im ep2im ep1im ep0im 176 (0xe3) usbei ep7i ep6i ep5i ep4i ep4i ep2i ep1i ep0i 175 (0xe2) usbpim - - - - sofim rmwuim resim susim 174 (0xe1) usbpi - - - feuri sofi rmwui resi susi 174 (0xe0) usbcr urmwu -upuc - - -usbe - 173 (0xdf) hsspidmab - - - hsspidmab [4..0] 309 (0xde) hsspidmadh - - hsspidmad [13..8] 309 (0xdd) hsspidmadl hsspidmad [7..0] 309 (0xdc) hsspidmacs - - - - - dmaerr dmadir dmar 307 (0xdb) hsspicr - - - - - sttto retto cs 304 (0xda) hsspiir timeout btd rcvof nssre nssfe - - - 302 (0xd9) hsspicfg spickdiv2 spickdiv1 spickdiv0 dpram cpha cpol mstr spien 301 (0xd8) hsspisr - rxbufrdy txbuffree dpramrdy nss rxbuff txbufe spickrdy 304 (0xd7) hsspitdr hsspitdd [7..0] 305 (0xd6) hsspirdr hsspirdd [7..0] 305 (0xd5) hsspigtr hsspigtd [7..0] 305 (0xd4) hsspiier timeoutie btdie rcvofie nssie - - - - 303 (0xd3) hsspicnt - - - hsspicnt [4..0] 305 (0xd2) hsspitoh spitimeout[15:8] 306 (0xd1) hsspitol spitimeout[7:0] 306 (0xd0) reserved - - - - - - - - (0xcf) reserved - - - - - - - - (0xce) reserved - - - - - - - - (0xcd) usbfcex epe - - - - epdir eptyp1 eptyp0 178 (0xcc) usbdbcex bct7 bct6 bc t5 bct4 bct3 bct2 bct1 bct0 178 (0xcb) usbcsex - ierr fstall txpb stsent rxsetup rcvd txc 176 (0xca) usbenum - - - - - enum2 enum1 enum0 176 (0xc9) reserved - - - - - - - - (0xc8) reserved - - - - - - - - (0xc7) reserved - - - - - - - - (0xc6) udr0 usart0 i/o data register 263 (0xc5) ubrr0h - - - - usart0 baud rate register high byte 267 (0xc4) ubrr0l usart0 baud rate register low byte 267 (0xc3) reserved - - - - - - - - (0xc2) ucsr0c umsel01 umsel00 upm01 u pm00 usbs0 ucsz01 ucsz00 ucpol0 265 (0xc1) ucsr0b rxcie0 txcie0 udrie0 rxen0 txen0 ucsz02 rxb80 txb80 264 (0xc0) ucsr0a rxc0 txc0 udre0 fe0 dor0 upe0 u2x0 mpcm0 263 (0xbf) reserved - - - - - - - -
at90scr100/116/132 432 tpr0327b ? vic ? 16fev11 (0xbe) reserved - - - - - - - - (0xbd) twamr twam6 twam5 twam4 twam3 twam2 twam1 twam0 - 341 (0xbc) twcr twint twea twsta twsto twwc twen -twie 339 (0xbb) twdr 2-wire serial interface data register 341 (0xba) twar twa6 twa5 twa4 twa3 twa2 twa1 twa0 twgce 341 (0xb9) twsr tws7 tws6 tws5 tws4 tws3 - twps1 twps0 340 (0xb8) twbr 2-wire serial interface bit rate register 338 (0xb7) reserved - - - - - - - - (0xb6) assr - exclk as2 tcn2ub ocr2aub ocr2bub tcr2aub tcr2bub 158 (0xb5) reserved - - - - - - - - (0xb4) ocr2b timer/counter2 output compare register b 158 (0xb3) ocr2a timer/counter2 output compare register a 157 (0xb2) tcnt2 timer/counter2 (8 bit) 157 (0xb1) tccr2b foc2a foc2b - - wgm22 cs22 cs21 cs20 156 (0xb0) tccr2a com2a1 com2a0 com2b1 com2b0 - -wgm21wgm20 153 (0xaf) updatx pdat [7..0] 242 (0xae) upienx flerre nakede - perre txstpe txoute rxstalle rxine 242 (0xad) upcfg2x intfrq [7..0] 238 (0xac) upstax cfgok overfi underfi - dtseq [1..0] - nbusyb 238 (0xab) upcfg1x - psize [0..2] pbk [0..1 alloc - 237 (0xaa) upcfg0x ptype [1..0] ptoken [0..1] pepnum [0..3] 236 (0xa9) upcrx -pfreezeinmode -rstdt - -pen 235 (0xa8) uprst - - - - p3rst p2rst p1rst p0rst 235 (0xa7) upnum - - - - - - pnum1 pnum0 235 (0xa6) upintx fifocon nakedi rwal perri txspi txouti rxstalli rxini 240 (0xa5) upinrqx inrq [7..0] 239 (0xa4) uhflen flen [7..0] 234 (0xa3) uhfnumh - - - - - fnum [10..8] 234 (0xa2) uhfnuml fnum [7..0] 234 (0xa1) uhaddr - haddr [6..0] 234 (0xa0) uhien - hwupe hsofe rxrsme rsmede rste ddisce dconne 233 (0x9f) uhint - hwupi hsofi rxrsmi rsmedi rsti ddisci dconni 232 (0x9e) uhcr uhen pad [1..0] frzclk - resume reset sofen 230 (0x9d) uperrx - counter [1..0] crc16 timeout pid datapid datatgl 239 (0x9c) upbcxh - - - - - pbytct [10..8] 243 (0x9b) upbcxl pbytct [7..0] 243 (0x9a) upint - - - - pint3 pint2 pint1 pint0 243 (0x99) uhsr - - - - speed - - - 231 (0x98) reserved - - - - - - - - (0x97) reserved - - - - - - - - (0x96) reserved - - - - - - - - (0x95) rngcr - - - - - - -rosce 344 (0x94) lfsr3 lfsd [31..24] 344 (0x93) lfsr2 lfsd [23..16] 344 (0x92) lfsr1 lfsd [15..8] 344 (0x91) lfsr0 lfsd [7..0] 344 (0x90) rdwdr rdd [7..0] 345 (0x8f) kbfr kbf7 kbf6 kbf5 kbf4 kbf3 kbf2 kbf1 kbf0 348 (0x8e) kber kbe7 kbe6 kbe5 kbe4 kbe3 kbe2 kbe1 kbe0 349 (0x8d) kblsr kbls7 kbls6 kbls5 kbls4 kbls3 kbls2 kbls1 kbls0 350 (0x8c) reserved - - - - - - - - (0x8b) ocr1bh timer/counter1 - output compare register b high byte 139 (0x8a) ocr1bl timer/counter1 - output compare register b low byte 139 (0x89) ocr1ah timer/counter1 - output compare register a high byte 139 (0x88) ocr1al timer/counter1 - output compare register a low byte 139 (0x87) icr1h timer/counter1 - input capture register high byte 139 (0x86) icr1l timer/counter1 - input capture register low byte 139 (0x85) tcnt1h timer/counter1 - counter register high byte 138 (0x84) tcnt1l timer/counter1 - counter register low byte 138 (0x83) reserved - - - - - - - - (0x82) tccr1c foc1a foc1b - - - - - - 137 (0x81) tccr1b icnc1 ices1 - wgm13 wgm12 cs12 cs11 cs10 136 (0x80) tccr1a com1a1 com1a0 com1b1 com1b0 - -wgm11wgm10 134 (0x7f) reserved - - - - - - - - (0x7e) reserved - - - - - - - - (0x7d) reserved - - - - - - - - (0x7c) reserved - - - - - - - - address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page
433 tpr0327b ? vic ? 16fev11 32. register summary at90scr100/116/132 (0x7b) aesdr data [0..8] 357 (0x7a) aesaddr addr [0..8] 357 (0x79) aesacr - - - - xor maninc autoinc kd 356 (0x78) aescr aesie aesif autokey keygn ks - encrypt aesgo 355 (0x77) reserved - - - - - - - - (0x76) reserved - - - - - - - - (0x75) ledcr led3 led2 led1 led0 85 (0x74) reserved - - - - - - - - (0x73) pcmsk3 pcint31 pcint30 pcint29 pcint28 pcint27 pcint26 pcint25 pcint24 81 (0x72) reserved - - - - - - - - (0x71) reserved - - - - - - - - (0x70) timsk2 - - - - - ocie2b ocie2a toie2 160 (0x6f) timsk1 - -icie1 - - ocie1b ocie1a toie1 140 (0x6e) timsk0 - - - - - ocie0b ocie0a toie0 111 (0x6d) pcmsk2 pcint23 pcint22 pcint21 pcint20 pcint19 pcint18 pcint17 pcint16 81 (0x6c) pcmsk1 pcint15 pcint14 pcint13 pcint12 pcint11 pcint10 pcint9 pcint8 81 (0x6b) pcmsk0 pcint7 pcint6 pcint5 pcint4 pcint3 pcint2 pcint1 pcint0 81 (0x6a) reserved - - - - - - - - (0x69) eicra isc31 isc30 isc21 isc20 isc11 isc10 isc01 isc00 77 (0x68) pcicr - - - - pcie3 pcie2 pcie1 pcie0 79 (0x67) reserved - - - - - - - - (0x66) reserved - - - - - - - - (0x65) prr1 - - prkb praes prsci prhsspi prusb prscusb 55 (0x64) prr0 prtwi prtim2 prtim0 - prtim1 prspi prusart0 - 54 (0x63) smoncr smonif smonie - - - - -smonen 68 (0x62) pllcr pllmux - - - - - lock on/off 48 (0x61) clkpr - - - - clkps3 clkps2 clkps1 clkps0 48 (0x60) wdtcsr wdif wdie wdp3 wdce wde wdp2 wdp1 wdp0 69 0x3f (0x5f) sreg i t h s v n z c 25 0x3e (0x5e) sph sp15 sp14 sp13 sp12 sp11 sp10 sp9 sp8 27 0x3d (0x5d) spl sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 27 0x3c (0x5c) reserved - - - - - - - - 0x3b (0x5b) reserved - - - - - - - - 0x3a (0x5a) reserved - - - - - - - - 0x39 (0x59) reserved - - - - - - - - 0x38 (0x58) reserved - - - - - - - - 0x37 (0x57) spmcsr spmie rwwsb sigrd rwwsre blbset pgwrt pgers spmen 381 0x36 (0x56) reserved - - - - - - - - 0x35 (0x55) mcucr jtd - -pud - - ivsel ivce 75, 90, 370 0x34 (0x54) mcusr - - - jtrf wdrf borf extrf porf 68 0x33 (0x53) smcr - - - -sm2sm1sm0se 53 0x32 (0x52) reserved - - - - - - - - 0x31 (0x51) ocdr d7/idrd d6 d5 d4 d3 d2 d1 d0 366 0x30 (0x50) reserved - - - - - - - - 0x2f (0x4f) reserved - - - - - - - - 0x2e (0x4e) spdr spi 0 data register 288 0x2d (0x4d) spsr spif wcol - - - - - spi2x 288 0x2c (0x4c) spcr spie spe dord mstr cpol cpha spr1 spr0 286 0x2b (0x4b) gpior2 general purpose i/o register 2 39 0x2a (0x4a) gpior1 general purpose i/o register 1 39 0x29 (0x49) reserved - - - - - - - - 0x28 (0x48) ocr0b timer/counter0 output compare register b 111 0x27 (0x47) ocr0a timer/counter0 output compare register a 111 0x26 (0x46) tcnt0 timer/counter0 (8 bit) 110 0x25 (0x45) tccr0b foc0a foc0b - - wgm02 cs02 cs01 cs00 109 0x24 (0x44) tccr0a com0a1 com0a0 com0b1 com0b0 - -wgm01wgm00 106 0x23 (0x43) gtccr tsm - - - - - psrasy psrsync 162 0x22 (0x42) eearh - - - - eearh [11:8] 34 0x21 (0x41) eearl eearl [7:0] 34 0x20 (0x40) eedr eeprom data register 34 0x1f (0x3f) eecr - - eepm1 eepm0 eerie eempe eepe eere 34 0x1e (0x3e) gpior0 general purpose i/o register 0 40 0x1d (0x3d) eimsk - - - - int3 int2 int1 int0 78 0x1c (0x3c) eifr - - - - intf3 intf2 intf1 intf0 78 0x1b (0x3b) pcifr - - - - pcif3 pcif2 pcif1 pcif0 80 0x1a (0x3a) eirr - - - - intd3 intd2 - - 79 0x19 (0x39) reserved - - - - - - - - address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page
at90scr100/116/132 434 tpr0327b ? vic ? 16fev11 0x18 (0x38) reserved - - - - - - - - 0x17 (0x37) tifr2 - - - - - ocf2b ocf2a tov2 161 0x16 (0x36) tifr1 - -icf1 - - ocf1b ocf1a tov1 140 0x15 (0x35) tifr0 - - - - - ocf0b ocf0a tov0 112 0x14 (0x34) reserved - - - - - - - - 0x13 (0x33) reserved - - - - - - - - 0x12 (0x32) reserved - - - - - - - - 0x11 (0x31) reserved - - - - - - - - 0x10 (0x30) reserved - - - - - - - - 0x0f (0x2f) reserved - - - - - - - - 0x0e (0x2e) porte porte7 porte6 porte 5 porte4 porte3 porte2 porte1 porte0 92 0x0d (0x2d) ddre dde7 dde6 dde5 dde4 dde3 dde2 dde1 dde0 93 0x0c (0x2c) pine pine7 pine6 pine5 pine4 pine3 pine2 pine1 pine0 93 0x0b (0x2b) portd portd7 portd6 portd5 portd4 portd3 portd2 portd1 portd0 92 0x0a (0x2a) ddrd ddd7 ddd6 ddd5 ddd4 ddd3 ddd2 ddd1 ddd0 92 0x09 (0x29) pind pind7 pind6 pi nd5 pind4 pind3 pi nd2 pind1 pind0 92 0x08 (0x28) portc - - portc5 portc4 portc3 portc2 portc1 portc0 92 0x07 (0x27) ddrc - - ddc5 ddc4 ddc3 ddc2 ddc1 ddc0 92 0x06 (0x26) pinc - - pinc5 pinc4 pinc3 pinc2 pinc1 pinc0 92 0x05 (0x25) portb portb7 portb6 portb 5 portb4 portb3 portb2 portb1 portb0 91 0x04 (0x24) ddrb ddb7 ddb6 ddb5 ddb4 ddb3 ddb2 ddb1 ddb0 91 0x03 (0x23) pinb pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 91 0x02 (0x22) porta porta7 porta6 porta 5 porta4 porta3 porta2 porta1 porta0 91 0x01 (0x21) ddra dda7 dda6 dda5 dda4 dda3 dda2 dda1 dda0 91 0x00 (0x20) pina pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 91 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page note note 1. for compatiliblity with future devices, reserved bits should be written to zero if accessed. reserved i/o memory addresses should never be written. 2. i/o registers within the address range $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 sbis and sbic instructions. 3. some of the status flags are cleared by writing a logical one to them. note that the cbi and sbi instructions will operate on all bits in the i/o register, writing a one back into any flag read as set, this clearing the flag. the cbi and sbi instructions work with registers $00 to $1f only. 4. when using the i/o specific commands in and out, the i/o addresses $00-$3f must be used. when addressing i/o registers as data space using ld and st instructions, $20 must be added to these addresses. the at90scr100/116/132 is a complex microcontroller with more peripheral units than can be supported within the 64 locations reserved in opcode for the in and out instructions. for the extended i/o space from $60-$ff, only the st/sts/std and ld/lds/ldd instructions ca be used. caution ! all ?reserved? registers must not be read or written. writing or reading these registers may generate unhandled state.
435 tpr0327b ? vic ? 16fev11 33. instruction set summary at90scr100/116/132 33. instruction set summary mnemonics operands description operation flags #clocks arithmetic and logic instructions add rd, rr add two registers rd rd + rr z,c,n,v,h 1 adc rd, rr add with carry two registers rd rd + rr + c z,c,n,v,h 1 adiw rdl,k add immediate to word rdh:rdl rdh:rdl + k z,c,n,v,s 2 sub rd, rr subtract two registers rd rd - rr z,c,n,v,h 1 subi rd, k subtract constant from register rd rd - k z,c,n,v,h 1 sbc rd, rr subtract with carry two registers rd rd - rr - c z,c,n,v,h 1 sbci rd, k subtract with carry constant from reg. rd rd - k - c z,c,n,v,h 1 sbiw rdl,k subtract immediate from word rdh:rdl rdh:rdl - k z,c,n,v,s 2 and rd, rr logical and registers rd rd ? rr z,n,v 1 andi rd, k logical and register and constant rd rd ? k z,n,v 1 or rd, rr logical or registers rd rd v rr z,n,v 1 ori rd, k logical or register and constant rd rd v k z,n,v 1 eor rd, rr exclusive or registers rd rd rr z,n,v 1 com rd one?s complement rd 0xff ? rd z,c,n,v 1 neg rd two?s complement rd 0x00 ? rd z,c,n,v,h 1 sbr rd,k set bit(s) in register rd rd v k z,n,v 1 cbr rd,k clear bit(s) in register rd rd ? (0xff - k) z,n,v 1 inc rd increment rd rd + 1 z,n,v 1 dec rd decrement rd rd ? 1 z,n,v 1 tst rd test for zero or minus rd rd ? rd z,n,v 1 clr rd clear register rd rd rd z,n,v 1 ser rd set register rd 0xff none 1 mul rd, rr multiply unsigned r1:r0 rd x rr z,c 2 muls rd, rr multiply signed r1:r0 rd x rr z,c 2 mulsu rd, rr multiply signed with unsigned r1:r0 rd x rr z,c 2 fmul rd, rr fractional multiply unsigned r1:r0 (rd x rr) << 1 z,c 2 fmuls rd, rr fractional multiply signed r1:r0 (rd x rr) << 1 z,c 2 fmulsu rd, rr fractional multiply signed with unsigned r1:r0 (rd x rr) << 1 z,c 2 branch instructions rjmp k relative jump pc pc + k + 1 none 2 ijmp indirect jump to (z) pc z none 2 jmp k direct jump pc k none 3 rcall k relative subroutine call pc pc + k + 1 none 4 icall indirect call to (z) pc z none 4 call k direct subroutine call pc k none 5 ret subroutine return pc stack none 5 reti interrupt return pc stack i 5 cpse rd,rr compare, skip if equal if (rd = rr) pc pc + 2 or 3 none 1/2/3 cp rd,rr compare rd ? rr z, n,v,c,h 1 cpc rd,rr compare with carry rd ? rr ? cz, n,v,c,h1 cpi rd,k compare register with immediate rd ? k z, n,v,c,h 1 sbrc rr, b skip if bit in register cleared if (rr(b)=0) pc pc + 2 or 3 none 1/2/3 sbrs rr, b skip if bit in register is set if (rr(b)=1) pc pc + 2 or 3 none 1/2/3 sbic p, b skip if bit in i/o register cleared if (p(b)=0) pc pc + 2 or 3 none 1/2/3 sbis p, b skip if bit in i/o register is set if (p(b)=1) pc pc + 2 or 3 none 1/2/3 brbs s, k branch if status flag set if (sreg(s) = 1) then pc pc+k + 1 none 1/2 brbc s, k branch if status flag cleared if (sreg(s) = 0) then pc pc+k + 1 none 1/2 breq k branch if equal if (z = 1) then pc pc + k + 1 none 1/2 brne k branch if not equal if (z = 0) then pc pc + k + 1 none 1/2 brcs k branch if carry set if (c = 1) then pc pc + k + 1 none 1/2 brcc k branch if carry cleared if (c = 0) then pc pc + k + 1 none 1/2 brsh k branch if same or higher if (c = 0) then pc pc + k + 1 none 1/2 brlo k branch if lower if (c = 1) then pc pc + k + 1 none 1/2 brmi k branch if minus if (n = 1) then pc pc + k + 1 none 1/2 brpl k branch if plus if (n = 0) then pc pc + k + 1 none 1/2 brge k branch if greater or equal, signed if (n v= 0) then pc pc + k + 1 none 1/2 brlt k branch if less than zero, signed if (n v= 1) then pc pc + k + 1 none 1/2 brhs k branch if half carry flag set if (h = 1) then pc pc + k + 1 none 1/2 brhc k branch if half carry flag cleared if (h = 0) then pc pc + k + 1 none 1/2 brts k branch if t flag set if (t = 1) then pc pc + k + 1 none 1/2 brtc k branch if t flag cleared if (t = 0) then pc pc + k + 1 none 1/2 brvs k branch if overflow flag is set if (v = 1) then pc pc + k + 1 none 1/2 brvc k branch if overflow flag is cleared if (v = 0) then pc pc + k + 1 none 1/2 brie k branch if interrupt enabled if ( i = 1) then pc pc + k + 1 none 1/2
at90scr100/116/132 436 tpr0327b ? vic ? 16fev11 brid k branch if interrupt disabled if ( i = 0) then pc pc + k + 1 none 1/2 bit and bit-test instructions sbi p,b set bit in i/o register i/o(p,b) 1 none 2 cbi p,b clear bit in i/o register i/o(p,b) 0 none 2 lsl rd logical shift left rd(n+1) rd(n), rd(0) 0 z,c,n,v 1 lsr rd logical shift right rd(n) rd(n+1), rd(7) 0 z,c,n,v 1 rol rd rotate left through carry rd(0) c,rd(n+1) rd(n),c rd(7) z,c,n,v 1 ror rd rotate right through carry rd(7) c,rd(n) rd(n+1),c rd(0) z,c,n,v 1 asr rd arithmetic shift right rd(n) rd(n+1), n=0..6 z,c,n,v 1 swap rd swap nibbles rd(3..0) rd(7..4),rd(7..4) rd(3..0) none 1 bset s flag set sreg(s) 1 sreg(s) 1 bclr s flag clear sreg(s) 0 sreg(s) 1 bst rr, b bit store from register to t t rr(b) t 1 bld rd, b bit load from t to register rd(b) t none 1 sec set carry c 1c1 clc clear carry c 0 c 1 sen set negative flag n 1n1 cln clear negative flag n 0 n 1 sez set zero flag z 1z1 clz clear zero flag z 0 z 1 sei global interrupt enable i 1i1 cli global interrupt disable i 0 i 1 ses set signed test flag s 1s1 cls clear signed test flag s 0 s 1 sev set twos complement overflow. v 1v1 clv clear twos complement overflow v 0 v 1 set set t in sreg t 1t1 clt clear t in sreg t 0 t 1 seh set half carry flag in sreg h 1h1 clh clear half carry flag in sreg h 0 h 1 data transfer instructions mov rd, rr move between registers rd rr none 1 movw rd, rr copy register word rd+1:rd rr+1:rr none 1 ldi rd, k load immediate rd k none 1 ld rd, x load indirect rd (x) none 2 ld rd, x+ load indirect and post-inc. rd (x), x x + 1 none 2 ld rd, - x load indirect and pre-dec. x x - 1, rd (x) none 2 ld rd, y load indirect rd (y) none 2 ld rd, y+ load indirect and post-inc. rd (y), y y + 1 none 2 ld rd, - y load indirect and pre-dec. y y - 1, rd (y) none 2 ldd rd,y+q load indirect with displacement rd (y + q) none 2 ld rd, z load indirect rd (z) none 2 ld rd, z+ load indirect and post-inc. rd (z), z z+1 none 2 ld rd, -z load indirect and pre-dec. z z - 1, rd (z) none 2 ldd rd, z+q load indirect with displacement rd (z + q) none 2 lds rd, k load direct from sram rd (k) none 2 st x, rr store indirect (x) rr none 2 st x+, rr store indirect and post-inc. (x) rr, x x + 1 none 2 st - x, rr store indirect and pre-dec. x x - 1, (x) rr none 2 st y, rr store indirect (y) rr none 2 st y+, rr store indirect and post-inc. (y) rr, y y + 1 none 2 st - y, rr store indirect and pre-dec. y y - 1, (y) rr none 2 std y+q,rr store indirect with displacement (y + q) rr none 2 st z, rr store indirect (z) rr none 2 st z+, rr store indirect and post-inc. (z) rr, z z + 1 none 2 st -z, rr store indirect and pre-dec. z z - 1, (z) rr none 2 std z+q,rr store indirect with displacement (z + q) rr none 2 sts k, rr store direct to sram (k) rr none 2 lpm load program memory r0 (z) none 3 lpm rd, z load program memory rd (z) none 3 lpm rd, z+ load program memory and post-inc rd (z), z z+1 none 3 elpm rd, z extended load program memory rd (z) none 3 spm store program memory (z) r1:r0 none - in rd, p in port rd p none 1 out p, rr out port p rr none 1 push rr push register on stack stack rr none 2 pop rd pop register from stack rd stack none 2 mnemonics operands description operation flags #clocks
437 tpr0327b ? vic ? 16fev11 33. instruction set summary at90scr100/116/132 mcu control instructions nop no operation none 1 sleep sleep (see specific descr. for sleep function) none 1 wdr watchdog reset (see specific descr. for wdr/timer) none 1 break break for on-chip debug only none n/a mnemonics operands description operation flags #clocks
at90scr100/116/132 438 tpr0327b ? vic ? 16fev11
439 tpr0327b ? vic ? 16fev11 at90scr100/116/132 reference list revision history document details title: datasheet preliminary literature number: tpr0327b date: 16fev11 ? revision b : ? new ?inside secure? template ? revision a: ? first release
tpr0327b ? vic ? 16fev11 headquarters product contact inside secure 41, parc club du golf 13586 aix-en-provence cedex 3 france tel: +33 (0)4-42-39-63-00 fax: +33 (0)4-42-39-63-19 web site www.insidesecure.com technical support scr@insidefr.com sales contact sales_web@insidefr.com disclaimer: all products are sold subject to inside secure terms & condi tions of sale and the provisions of any agreements made between in side secure and the customer. in ordering a product covered by this document the customer agrees to be bound by those terms & conditions an d agreements and nothing contained in this document constitutes or forms part of a contract (with the exception of the contents of this notice). a copy of inside secure? terms & condi- tions of sale is available on request. export of any inside secure product outside of the eu may require an export licence. the information in this document is provided in connection with in side secure products. no license, express or implied, by esto ppel or otherwise, to any intel- lectual property right is granted by this document or in connection with the sale of inside secure products. except as set forth in inside secure?s terms and conditions of sale, inside secure or its suppliers or licensors assume no liability whatsoever and disclaims any express, implied or statutory warranty relating to its products including, but not limited to, the implied warranty of merchantability, satisfactory quality, fitness for a particular purpose, or non-infringement. in no event shall inside secure be liable for any direct, indirect, consequential, punitive, exemplary, special or incidental damages (including, without limitation, damages for loss of profits, loss of revenue, business interruption, loss of goodwill, or loss of information or data) notwithstanding the theory of liability under which said damages are sought, including but not lim- ited to contract, tort (including negligence), products liability, strict liability, statutory liability or otherwise, even if inside secure has been advised of the possibility of such damages . inside secure makes no representations or warranties with respec t to the accuracy or completeness of the contents of this docum ent and reserves the right to make changes to specifications and product descriptions at any time without notice. inside secure does not make any commitment to update the information contained herein. inside secure advises its customers to obtain the latest version of device data sheets to verify, before plac ing orders, that the information being relied upon by the customer is current. inside secure prod ucts are not intended, authorized, or warranted for use as crit ical components in life support devices, systems or applications, unless a spec ific written agreement pertaining to such intended use is executed between the m anufacturer and inside secure. life support devices, systems or a pplications are devices, system s or applications that (a) are intended for surgical i mplant to the body or (b) support or sustain life, and which defect or failure to perform can be r easonably expected to result in an injury to the user. a critical component is any component of a life support device, system or application which failure to perform can be reasonabl y expected to cause the failure of the life support device, system or application, or to affect its safety or effectiveness. the security of any system in which the product is used will depend on the system?s security as a whole. where security or cryp tography features are mentioned in this document this refers to features which are intended to increase the security of the product under normal use and in nor mal circumstances. ? inside secure 2011. all rights reserved. inside secure ?, inside secure logo and combinations thereof, and others are registe red trademarks or trade- names of inside secure or its subsidiaries. other terms and product names may be trademarks of others.


▲Up To Search▲   

 
Price & Availability of AT90SCR100LHS-Z1R

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]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X