Features • High-performance, Low-power AVR® 8-bit Microcontroller • Advanced RISC Architecture • • • • • • • • • – 133 Powerful Instructions – Most Single Clock Cycle Execution – 32 x 8 General Purpose Working Registers + Peripheral Control Registers – Fully Static Operation – Up to 16 MIPS Throughput at 16 MHz – On-chip 2-cycle Multiplier Non volatile Program and Data Memories – 32K/64K/128K Bytes of In-System Reprogrammable Flash (AT90CAN32/64/128) • Endurance: 10,000 Write/Erase Cycles – Optional
1. Description 1.1 Comparison Between AT90CAN32, AT90CAN64 and AT90CAN128 AT90CAN32, AT90CAN64 and AT90CAN128 are hardware and software compatible. They differ only in memory sizes as shown in Table 1-1. 1.2 Table 1-1.
AT90CAN32/64/128 combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel AT90CAN32/64/128 is a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications. The AT90CAN32/64/128 AVR is supported with a full suite of program and system development tools including: C compilers, macro assemblers, program debugger/simulators, in-circuit emulators, and evaluation kits. 1.
Block Diagram PF7 - PF0 VCC PC7 - PC0 PA7 - PA0 PORTA DRIVERS PORTF DRIVERS RESET Block Diagram XTAL2 Figure 1-1. XTAL1 1.4 PORTC DRIVERS GND DATA DIR. REG. PORTF DATA REGISTER PORTF DATA DIR. REG. PORTA DATA REGISTER PORTA DATA REGISTER PORTC DATA DIR. REG. PORTC 8-BIT DATA BUS POR - BOD RESET AVCC INTERNAL OSCILLATOR CALIB.
AT90CAN32/64/128 Pin Configurations GND AREF PF0 (ADC0) PF1 (ADC1) PF2 (ADC2) PF3 (ADC3) PF4 (ADC4 / TCK) PF5 (ADC5 / TMS) PF6 (ADC6 / TDO) PF7 (ADC7 / TDI) GND VCC PA0 (AD0) PA1 (AD1) PA2 (AD2) 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 Pinout AT90CAN32/64/128 - TQFP AVCC NC (1) 1 48 PA3 (AD3) (RXD0 / PDI) PE0 2 47 PA4 (AD4) (TXD0 / PDO) PE1 3 46 PA5 (AD5) (XCK0 / AIN0) PE2 4 45 PA6 (AD6) (OC3A / AIN1) PE3 5 44 PA7 (AD7) (OC3B / INT4) PE4 6 43 PG2 (
AVCC GND AREF PF0 (ADC0) PF1 (ADC1) PF2 (ADC2) PF3 (ADC3) PF4 (ADC4 / TCK) PF5 (ADC5 / TMS) PF6 (ADC6 / TDO) PF7 (ADC7 / TDI) GND VCC PA0 (AD0) PA1 (AD1) PA2 (AD2) 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 PA3 (AD3) 2 47 PA4 (AD4) (TXD0 / PDO) PE1 3 46 PA5 (AD5) (XCK0 / AIN0) PE2 4 45 PA6 (AD6) (OC3A / AIN1) PE3 5 44 PA7 (AD7) INDEX CORNER (OC3B / INT4) PE4 6 43 PG2 (ALE) (OC3C / INT5) PE5 7 42 PC7 (A15 / CLKO) (T3 / INT6) PE6 8 41 PC6 (A14) (ICP
AT90CAN32/64/128 1.6.3 Port A (PA7..PA0) Port A is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port A pins that are externally pulled low will source current if the pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.
Port F also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal pull-up resistors (selected for each bit). The Port F output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port F pins that are externally pulled low will source current if the pull-up resistors are activated. The Port F pins are tri-stated when a reset condition becomes active, even if the clock is not running.
AT90CAN32/64/128 3. AVR CPU Core 3.1 Introduction This section discusses the AVR core architecture in general. The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. 3.2 Architectural Overview Figure 3-1.
The fast-access Register File contains 32 x 8-bit general purpose working registers with a single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a typical ALU operation, two operands are output from the Register File, the operation is executed, and the result is stored back in the Register File – in one clock cycle.
AT90CAN32/64/128 3.4 Status Register The Status Register contains information about the result of the most recently executed arithmetic instruction. This information can be used for altering program flow in order to perform conditional 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.
• Bit 0 – C: Carry Flag The Carry Flag C indicates a carry in an arithmetic or logic operation. See the “Instruction Set Description” for detailed information. 3.5 General Purpose Register File The Register File is optimized for the AVR Enhanced RISC instruction set.
AT90CAN32/64/128 Figure 3-3. The X-, Y-, and Z-registers 15 X-register XH XL 7 0 R27 (0x1B) YH YL 7 0 R29 (0x1D) Z-register 0 R26 (0x1A) 15 Y-register 0 7 0 7 0 R28 (0x1C) 15 ZH 7 0 ZL 7 R31 (0x1F) 0 0 R30 (0x1E) In the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement (see the instruction set reference for details). 3.5.
3.6 Stack Pointer The Stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. The Stack Pointer Register always points to the top of the Stack. Note that the Stack is implemented as growing from higher memory locations to lower memory locations. This implies that a Stack PUSH command decreases the Stack Pointer.
AT90CAN32/64/128 Figure 3-6 shows the internal timing concept for the Register File. In a single clock cycle an ALU operation using two register operands is executed, and the result is stored back to the destination register. Figure 3-6. Single Cycle ALU Operation T1 T2 T3 T4 clkCPU Total Execution T ime Register Operands Fetch ALU Operation Execute Result Write Back 3.8 Reset and Interrupt Handling The AVR provides several different interrupt sources.
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 AVR exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served.
AT90CAN32/64/128 3.8.2 Interrupt Response Time The interrupt execution response for all the enabled AVR interrupts is four clock cycles minimum. After four clock cycles the program vector address for the actual interrupt handling routine is executed. During this four clock cycle period, the Program Counter is pushed onto the Stack. The vector is normally a jump to the interrupt routine, and this jump takes three clock cycles.
4. Memories This section describes the different memories in the AT90CAN32/64/128. The AVR architecture has two main memory spaces, the Data Memory and the Program Memory space. In addition, the AT90CAN32/64/128 features an EEPROM Memory for data storage. All three memory spaces are linear and regular. Table 4-1. Memory Mapping.
AT90CAN32/64/128 Constant tables can be allocated within the entire program memory address space (see the LPM – Load Program Memory and ELPM – Extended Load Program Memory instruction description). Timing diagrams for instruction fetch and execution are presented in “Instruction Execution Timing” on page 14. Figure 4-1. Program Memory Map Program Memory 0x0000 Application Flash Section Boot Flash Section Flash end 4.2 SRAM Data Memory Figure 4-2 shows how the AT90CAN32/64/128 SRAM Memory is organized.
4.2.1 SRAM Data Access When the addresses accessing the SRAM memory space exceeds the internal data memory locations, the external data SRAM is accessed using the same instructions as for the internal data memory access. When the internal data memories are accessed, the read and write strobe pins (PG0 and PG1) are inactive during the whole access cycle. External SRAM operation is enabled by setting the SRE bit in the XMCRA Register.
AT90CAN32/64/128 Figure 4-2. Data Memory Map Data Memory 32 Registers 64 I/O Registers 160 Ext I/O Reg. 0x0000 - 0x001F 0x0020 - 0x005F 0x0060 - 0x00FF ISRAM start Internal SRAM (ISRAM size) ISRAM end XMem start External SRAM (XMem size) 0xFFFF 4.2.2 SRAM Data Access Times This section describes the general access timing concepts for internal memory access. The internal data SRAM access is performed in two clkCPU cycles as described in Figure 4-3. Figure 4-3.
4.3 EEPROM Data Memory The AT90CAN32/64/128 contains EEPROM memory (see “E2 size”). 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, specifying the EEPROM Address Registers, the EEPROM Data Register, and the EEPROM Control Register.
AT90CAN32/64/128 4.3.3 The EEPROM Data Register – EEDR Bit 7 6 5 4 3 2 1 0 EEDR7 EEDR6 EEDR5 EEDR4 EEDR3 EEDR2 EEDR1 EEDR0 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 EEDR • 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 given by the EEAR Register.
Support – Read-While-Write Self-Programming” on page 321 for details about Boot programming. Caution: An interrupt between step 5 and step 6 will make the write cycle fail, since the EEPROM Master Write Enable will time-out. If an interrupt routine accessing the EEPROM is interrupting another EEPROM access, the EEAR or EEDR Register will be modified, causing the interrupted EEPROM access to fail. It is recommended to have the Global Interrupt Flag cleared during all the steps to avoid these problems.
AT90CAN32/64/128 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 globally) so that no interrupts will occur during execution of these functions. The examples also assume that no Flash Boot Loader is present in the software. If such code is present, the EEPROM write function must also wait for any ongoing SPM command to finish.
The next code examples show assembly and C functions for reading the EEPROM. The examples assume that interrupts are controlled so that no interrupts will occur during execution of these functions.
AT90CAN32/64/128 4.4 I/O Memory The I/O space definition of the AT90CAN32/64/128 is shown in “Register Summary” on page 405. All AT90CAN32/64/128 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.
Figure 4-4. External Memory with Sector Select 0x0000 Internal memory ISRAM end XMem start Lower sector SRW01 SRW00 SRL[2..0] External Memory (0-64K x 8) Upper sector SRW11 SRW10 0xFFFF 4.5.2 Using the External Memory Interface The interface consists of: • AD7:0: Multiplexed low-order address bus and data bus. • A15:8: High-order address bus (configurable number of bits). • ALE: Address latch enable. • RD: Read strobe. • WR: Write strobe.
AT90CAN32/64/128 4.5.3 Address Latch Requirements Due to the high-speed operation of the XRAM interface, the address latch must be selected with care for system frequencies above 8 MHz @ 4V and 4 MHz @ 2.7V. When operating at conditions above these frequencies, the typical old style 74HC series latch becomes inadequate. The External Memory Interface is designed in compliance to the 74AHC series latch. However, most latches can be used as long they comply with the main timing parameters.
address actually is driven on the bus. The access time cannot exceed the time from the ALE pulse must be asserted low until data is stable during a read sequence (see tLLRL+ tRLRH - tDVRH in Table 26-7 through Table 26-14). The different wait-states are set up in software. As an additional feature, it is possible to divide the external memory space in two sectors with individual wait-state settings.
AT90CAN32/64/128 Note: 1. SRWn1 = SRW11 (upper sector) or SRW01 (lower sector), SRWn0 = SRW10 (upper sector) or SRW00 (lower sector). The ALE pulse in period T5 is only present if the next instruction accesses the RAM (internal or external). Figure 4-8. External Data Memory Cycles with SRWn1 = 1 and SRWn0 = 0(1) T1 T2 T3 T4 T5 T6 System Clock (CLK CPU ) ALE A15:8 Prev. addr. DA7:0 Prev. data Address DA7:0 (XMBK = 0) Prev. data Address DA7:0 (XMBK = 1) Prev.
4.5.6 External Memory Control Register A – XMCRA Bit 7 6 5 4 3 2 1 0 SRE SRL2 SRL1 SRL0 SRW11 SRW10 SRW01 SRW00 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 XMCRA • Bit 7 – SRE: External SRAM/XMEM Enable Writing SRE to one enables the External Memory Interface.The pin functions AD7:0, A15:8, ALE, WR, and RD are activated as the alternate pin functions. The SRE bit overrides any pin direction settings in the respective data direction registers.
AT90CAN32/64/128 • Bit 3..2 – SRW11, SRW10: Wait-state Select Bits for Upper Sector The SRW11 and SRW10 bits control the number of wait-states for the upper sector of the external memory address space, see Table 4-4. • Bit 1..0 – SRW01, SRW00: Wait-state Select Bits for Lower Sector The SRW01 and SRW00 bits control the number of wait-states for the lower sector of the external memory address space, see Table 4-4. Table 4-4.
Table 4-5. 4.5.8 Port C Pins Released as Normal Port Pins when the External Memory is Enabled XMM2 XMM1 XMM0 # Bits for External Memory Address Released Port Pins 0 0 0 8 (Full External Memory Space) None 0 0 1 7 PC7 0 1 0 6 PC7 .. PC6 0 1 1 5 PC7 .. PC5 1 0 0 4 PC7 .. PC4 1 0 1 3 PC7 .. PC3 1 1 0 2 PC7 ..
AT90CAN32/64/128 4.5.9 Using all 64KB Locations of External Memory Since the External Memory is mapped after the Internal Memory as shown in Figure 4-4, only (64K-(“ISRAM size”+256)) bytes of External Memory is available by default (address space 0x0000 to “ISRAM end” is reserved for internal memory). However, it is possible to take advantage of the entire External Memory by masking the higher address bits to zero.
4.6 General Purpose I/O Registers The AT90CAN32/64/128 contains three General Purpose I/O Registers. These registers can be used for storing any information, and they are particularly useful for storing global variables and status flags. The General Purpose I/O Register 0, within the address range 0x00 - 0x1F, is directly bit-accessible using the SBI, CBI, SBIS, and SBIC instructions. 4.6.
AT90CAN32/64/128 5. System Clock 5.1 Clock Systems and their Distribution Figure 5-1 presents the principal clock systems in the AVR and their distribution. All of the clocks need not be active at a given time. In order to reduce power consumption, the clocks to unused modules can be halted by using different sleep modes, as described in “Power Management and Sleep Modes” on page 46. The clock systems are detailed below. Figure 5-1.
5.1.4 Asynchronous Timer Clock – clkASY The Asynchronous Timer clock allows the Asynchronous Timer/Counter to be clocked directly from an external clock or an external 32 kHz clock crystal. The dedicated clock domain allows using this Timer/Counter as a real-time counter even when the device is in sleep mode. 5.1.5 ADC Clock – clkADC The ADC is provided with a dedicated clock domain. This allows halting the CPU and I/O clocks in order to reduce noise generated by digital circuitry.
AT90CAN32/64/128 5.4 Crystal Oscillator XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can be configured for use as an On-chip Oscillator, as shown in Figure 5-2. Either a quartz crystal or a ceramic resonator may be used. C1 and C2 should always be equal for both crystals and resonators. The optimal value of the capacitors depends on the crystal or resonator in use, the amount of stray capacitance, and the electromagnetic noise of the environment.
Table 5-4. Start-up Times for the Oscillator Clock Selection CKSEL0 SUT1..0 Start-up Time from Power-down and Power-save Additional Delay from Reset (VCC = 5.0V) Recommended Usage 0 00 258 CK(1) 14 CK + 4.1 ms Ceramic resonator, fast rising power 0 01 258 CK(1) 14 CK + 65 ms Ceramic resonator, slowly rising power 0 10 1K CK(2) 14 CK Ceramic resonator, BOD enabled 0 11 1K CK(2) 14 CK + 4.
AT90CAN32/64/128 When this Oscillator is selected, start-up times are determined by the SUT1..0 fuses as shown in Table 5-5 and CKSEL1..0 fuses as shown in Table 5-6. Table 5-5. Start-up Times for the Low-frequency Crystal Oscillator Clock Selection SUT1..0 Additional Delay from Reset (VCC = 5.0V) 00 14 CK 01 14 CK + 4.1 ms Slowly rising power 10 14 CK + 65 ms Stable frequency at start-up 11 Start-up Times for the Low-frequency Crystal Oscillator Clock Selection CKSEL3..
When this Oscillator is selected, start-up times are determined by the SUT Fuses as shown in Table 5-8. Table 5-8. Start-up times for the internal calibrated RC Oscillator clock selection SUT1..0 Start-up Time from Powerdown and Power-save Additional Delay from Reset (VCC = 5.0V) 00 6 CK 14 CK 01 6 CK 14 CK + 4.1 ms Fast rising power 10(1) 6 CK 14 CK + 65 ms Slowly rising power 11 Note: 5.6.1 Recommended Usage BOD enabled Reserved 1. The device is shipped with this option selected.
AT90CAN32/64/128 Figure 5-4. External Clock Drive Configuration NC XTAL2 External Clock Signal XTAL1 GND Table 5-10. External Clock Frequency CKSEL3..0 Frequency Range 0000 0 - 16 MHz When this clock source is selected, start-up times are determined by the SUT Fuses as shown in Table 5-11. Table 5-11. Start-up Times for the External Clock Selection SUT1..0 Start-up Time from Powerdown and Power-save Additional Delay from Reset (VCC = 5.0V) 00 6 CK 14 CK 01 6 CK 14 CK + 4.
AT90CAN32/64/128 share the Timer/Counter2 Oscillator Pins (TOSC1 and TOSC2) with PG4 and PG3. This means that both PG4 and PG3 can only be used when the Timer/Counter2 Oscillator is not enable. Applying an external clock source to TOSC1 can be done in asynchronous operation if EXTCLK in the ASSR Register is written to logic one. See “Asynchronous operation of the Timer/Counter2” on page 160 for further description on selecting external clock as input instead of a 32 kHz crystal.
AT90CAN32/64/128 “0011”, giving a division factor of 8 at start up. This feature should be used if the selected clock source has a higher frequency than the maximum frequency of the device at the present operating conditions. Note that any value can be written to the CLKPS bits regardless of the CKDIV8 Fuse setting.
6. Power Management and Sleep Modes Sleep modes enable the application to shut down unused modules in the MCU, thereby saving power. The AVR provides various sleep modes allowing the user to tailor the power consumption to the application’s requirements. To enter any of the five sleep modes, the SE bit in SMCR must be written to logic one and a SLEEP instruction must be executed.
AT90CAN32/64/128 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. 6.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 SPI, CAN, USART, Analog Comparator, ADC, Two-wire Serial Interface, Timer/Counters, Watchdog, and the interrupt system to continue operating.
If Timer/Counter2 is clocked asynchronously, i.e., the AS2 bit in ASSR is set, Timer/Counter2 will run 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.
AT90CAN32/64/128 6.6.2 Analog Comparator When entering Idle mode, the Analog Comparator should be disabled if not used. When entering ADC Noise Reduction mode, the Analog Comparator should be disabled. In other sleep modes, the Analog Comparator is automatically disabled. However, if the Analog Comparator is set up to use the Internal Voltage Reference as input, the Analog Comparator should be disabled in all sleep modes. Otherwise, the Internal Voltage Reference will be enabled, independent of sleep mode.
this will contribute significantly to the total current consumption. There are three alternative ways to avoid this: • Disable OCDEN Fuse. • Disable JTAGEN Fuse. • Write one to the JTD bit in MCUCR. The TDO pin is left floating when the JTAG interface is enabled while the JTAG TAP controller is not shifting data. If the hardware connected to the TDO pin does not pull up the logic level, power consumption will increase.
AT90CAN32/64/128 7. System Control and Reset 7.1 7.1.1 Reset Resetting the AVR During reset, all I/O Registers are set to their initial values, and the program starts execution from the Reset Vector. The instruction placed at the Reset Vector must be a JMP – Absolute Jump – instruction to the reset handling routine. If the program never enables an interrupt source, the Interrupt Vectors are not used, and regular program code can be placed at these locations.
Figure 7-1. Reset Logic DATA BUS PORF BORF EXTRF WDRF JTRF MCU Status Register (MCUSR) Power-on Reset Circuit Brown-out Reset Circuit BODLEVEL [2..0] Pull-up Resistor Spike Filter JTAG Reset Register Watchdog Oscillator Clock Generator CK Delay Counters TIMEOUT CKSEL[3:0] SUT[1:0] Table 7-1. Symbol Reset Characteristics Parameter Condition Min.
AT90CAN32/64/128 VCC rise. The RESET signal is activated again, without any delay, when VCC decreases below the detection level. Figure 7-2. MCU Start-up, RESET Tied to VCC VCCRR VCC VPOR RESET VPOT VCCRR tTOUT TIME-OUT INTERNAL RESET Figure 7-3. MCU Start-up, RESET Extended Externally VCCRR VCC VPOR RESET TIME-OUT VRST tTOUT INTERNAL RESET Note: 7.1.4 If VPOR or VCCRR parameter range can not be followed, an External Reset is required.
Figure 7-4. External Reset During Operation CC 7.1.5 Brown-out Detection AT90CAN32/64/128 has an On-chip Brown-out Detection (BOD) circuit for monitoring the VCC level during operation by comparing it to a fixed trigger level. The trigger level for the BOD can be selected by the BODLEVEL Fuses. The trigger level has a hysteresis to ensure spike free Brown-out Detection. The hysteresis on the detection level should be interpreted as V BOT+ = VBOT + VHYST/2 and VBOT- = VBOT - VHYST/2. Table 7-2.
AT90CAN32/64/128 (VBOT+ in Figure 7-5), the delay counter starts the MCU after the Time-out period tTOUT has expired. The BOD circuit will only detect a drop in VCC if the voltage stays below the trigger level for longer than tBOD given in Table 7-3. Figure 7-5. Brown-out Reset During Operation VCC VBOT- VBOT+ RESET tTOUT TIME-OUT INTERNAL RESET 7.1.6 Watchdog Reset When the Watchdog times out, it will generate a short reset pulse of one CK cycle duration.
7.1.7 MCU Status Register – MCUSR The MCU Status Register provides information on which reset source caused an MCU reset. Bit 7 6 5 4 3 2 1 0 – – – JTRF WDRF BORF EXTRF PORF Read/Write R R R R/W R/W R/W R/W R/W Initial Value 0 0 0 MCUSR See Bit Description • Bit 7..5 – Reserved Bits These bits are reserved for future use.
AT90CAN32/64/128 ADC is used. To reduce power consumption in Power-down mode, the user can avoid the three conditions above to ensure that the reference is turned off before entering Power-down mode. 7.2.2 Voltage Reference Characteristics Table 7-4. Symbol 7.3 Internal Voltage Reference Characteristics Parameter Condition Min. Typ. Max. Units 1.0 1.1 1.
7.3.1 Watchdog Timer Control Register – WDTCR Bit 7 6 5 4 3 2 1 0 – – – WDCE WDE WDP2 WDP1 WDP0 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 WDTCR • Bits 7..5 – Reserved Bits These bits are reserved bits for future use. • Bit 4 – WDCE: Watchdog Change Enable This bit must be set when the WDE bit is written to logic zero. Otherwise, the Watchdog will not be disabled. Once written to one, hardware will clear this bit after four clock cycles.
AT90CAN32/64/128 The following code example shows one assembly and one C function for turning off the WDT. The example assumes that interrupts are controlled (e.g. by disabling interrupts globally) so that no interrupts will occur during execution of these functions.
8. Interrupts This section describes the specifics of the interrupt handling as performed in AT90CAN32/64/128. For a general explanation of the AVR interrupt handling, refer to “Reset and Interrupt Handling” on page 15. 8.1 Interrupt Vectors in AT90CAN32/64/128 Table 8-1. 60 Reset and Interrupt Vectors Vector No.
AT90CAN32/64/128 Table 8-1. Reset and Interrupt Vectors (Continued) Vector No.
0x0012 jmp TIM2_COMP ; Timer2 Compare Handler 0x0014 jmp TIM2_OVF 0x0016 jmp TIM1_CAPT ; Timer1 Capture Handler 0x0018 jmp TIM1_COMPA; Timer1 CompareA Handler 0x001A jmp TIM1_COMPB; Timer1 CompareB Handler 0x001C jmp TIM1_OVF ; Timer1 CompareC Handler 0x001E jmp TIM1_OVF ; Timer1 Overflow Handler 0x0020 jmp TIM0_COMP ; Timer0 Compare Handler 0x0022 jmp TIM0_OVF ; Timer0 Overflow Handler 0x0024 jmp CAN_IT ; CAN Handler 0x0026 jmp CTIM_OVF ; CAN Timer Overflow Handler 0x0
AT90CAN32/64/128 0x0004 sei 0x0005 ; Enable interrupts xxx ; .org (BootResetAdd + 0x0002) 0x..02 jmp EXT_INT0 ; IRQ0 Handler 0x..04 jmp PCINT0 ; PCINT0 Handler ... ... ... ; 0x..0C jmp SPM_RDY ; Store Program Memory 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 .
8.2 Moving Interrupts Between Application and Boot Space The General Interrupt Control Register controls the placement of the Interrupt Vector table. 8.2.1 MCU Control Register – MCUCR Bit 7 6 5 4 3 2 1 0 JTD – – PUD – – IVSEL IVCE Read/Write R/W R R R/W R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 MCUCR • 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.
AT90CAN32/64/128 • 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.
9. I/O-Ports 9.1 Introduction All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the SBI and CBI instructions. The same applies when changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input).
AT90CAN32/64/128 9.2 Ports as General Digital I/O The ports are bi-directional I/O ports with optional internal pull-ups. Figure 9-2 shows a functional description of one I/O-port pin, here generically called Pxn. Figure 9-2. General Digital I/O(1) PUD Q D DDxn Q CLR WDx RESET 1 Q Pxn D 0 PORTxn Q CLR WPx DATA BUS RDx RESET WRx SLEEP RRx SYNCHRONIZER D Q L Q D RPx Q PINxn Q clk I/O PUD: PULLUP DISABLE SLEEP: SLEEP CONTROL clkI/O : I/O CLOCK Note: 9.2.
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). 9.2.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. 9.2.
AT90CAN32/64/128 Figure 9-3. Synchronization when Reading an Externally Applied Pin value SYSTEM CLK INSTRUCTIONS XXX XXX in r17, PINx SYNC LATCH PINxn r17 0x00 0xFF t pd, max t pd, min Consider the clock period starting shortly after the first falling edge of the system clock. The latch is closed when the clock is low, and goes transparent when the clock is high, as indicated by the shaded region of the “SYNC LATCH” signal. The signal value is latched when the system clock goes low.
The following code example shows how to set port B pins 0 and 1 high, 2 and 3 low, and define the port pins from 4 to 7 as input with pull-ups assigned to port pins 6 and 7. The resulting pin values are read back again, but as previously discussed, a nop instruction is included to be able to read back the value recently assigned to some of the pins. Assembly Code Example(1) ...
AT90CAN32/64/128 above mentioned sleep modes, as the clamping in these sleep modes produces the requested logic change. 9.2.6 9.3 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, floating inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (Reset, Active mode and Idle mode).
Figure 9-5.
AT90CAN32/64/128 Table 9-2. Generic Description of Overriding Signals for Alternate Functions Signal Name Full Name Description PUOE Pull-up Override Enable If this signal is set, the pull-up enable is controlled by the PUOV signal. If this signal is cleared, the pull-up is enabled when {DDxn, PORTxn, PUD} = 0b010. PUOV Pull-up Override Value If PUOE is set, the pull-up is enabled/disabled when PUOV is set/cleared, regardless of the setting of the DDxn, PORTxn, and PUD Register bits.
• 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 “Configuring the Pin” for more details about this feature. 9.3.2 Alternate Functions of Port A The Port A has an alternate function as the address low byte and data lines for the External Memory Interface. The Port A pins with alternate functions are shown in Table 9-3. Table 9-3.
AT90CAN32/64/128 Table 9-4 and Table 9-5 relates the alternate functions of Port A to the overriding signals shown in Figure 9-5 on page 72. Table 9-4. Overriding Signals for Alternate Functions in PA7..
9.3.3 Alternate Functions of Port B The Port B pins with alternate functions are shown in Table 9-6. Table 9-6.
AT90CAN32/64/128 MOSI, SPI Master Data output, Slave Data input for SPI channel. When the SPI is enabled as a slave, this pin is configured as an input regardless of the setting of DDB2. When the SPI is enabled as a master, the data direction of this pin is controlled by DDB2. When the pin is forced to be an input, the pull-up can still be controlled by the PORTB2 bit. • SCK – Port B, Bit 1 SCK, Master Clock output, Slave Clock input pin for SPI channel.
Table 9-8. 9.3.4 Overriding Signals for Alternate Functions in PB3..
AT90CAN32/64/128 • A14 – Port C, Bit 6 A14, External memory interface address 14. • A13 – Port C, Bit 5 A13, External memory interface address 13. • A12 – Port C, Bit 4 A12, External memory interface address 12. • A11 – Port C, Bit 3 A11, External memory interface address 11. • A10 – Port C, Bit 2 A10, External memory interface address 10. • A9 – Port C, Bit 1 A9, External memory interface address 9. • A8 – Port C, Bit 0 A8, External memory interface address 8.
Table 9-11. 9.3.5 Overriding Signals for Alternate Functions in PC3..
AT90CAN32/64/128 TXCAN, CAN Transmit Data (Data output pin for the CAN). When the CAN is enabled, this pin is configured as an output regardless of the value of DDD5. XCK1, USART1 External clock. The Data Direction Register (DDD5) controls whether the clock is output (DDD5 set) or input (DDD45 cleared). The XCK1 pin is active only when the USART1 operates in Synchronous mode. • ICP1 – Port D, Bit 4 ICP1, Input Capture Pin1. The PD4 pin can act as an input capture pin for Timer/Counter1.
Table 9-13 and Table 9-14 relates the alternate functions of Port D to the overriding signals shown in Figure 9-5 on page 72. Table 9-13.
AT90CAN32/64/128 9.3.6 Alternate Functions of Port E The Port E pins with alternate functions are shown in Table 9-15. Table 9-15.
• AIN0/XCK0 – Port E, Bit 2 AIN0 – Analog Comparator Positive input. This pin is directly connected to the positive input of the Analog Comparator. XCK0, USART0 External clock. The Data Direction Register (DDE2) controls whether the clock is output (DDE2 set) or input (DDE2 cleared). The XCK0 pin is active only when the USART0 operates in Synchronous mode. • PDO/TXD0 – Port E, Bit 1 PDO, SPI Serial Programming Data Output.
AT90CAN32/64/128 Table 9-17. Signal Name PE3/AIN1/OC3A PE2/AIN0/XCK0 PE1/PDO/TXD0 PE0/PDI/RXD0 PUOE 0 0 TXEN0 RXEN0 PUOV 0 0 0 PORTE0 • PUD DDOE 0 0 TXEN0 RXEN0 DDOV 0 0 1 0 PVOE OC3A ENABLE UMSEL0 TXEN0 0 PVOV OC3A XCK0 OUTPUT TXD0 0 PTOE 0 0 0 0 (1) (1) DIEOE AIN1D AIN0D 0 0 DIEOV 0 0 0 0 DI 0 XCK0 INPUT – RXD0 AIO AIN1 INPUT AIN0 INPUT – – Note: 9.3.7 Overriding Signals for Alternate Functions in PE3..PE0 1.
TDI, JTAG Test Data In. Serial input data to be shifted in to the Instruction Register or Data Register (scan chains). When the JTAG interface is enabled, this pin can not be used as an I/O pin. • TCK, ADC6 – Port F, Bit 6 ADC6, Analog to Digital Converter, input channel 6. TDO, JTAG Test Data Out. Serial output data from Instruction Register or Data Register. When the JTAG interface is enabled, this pin can not be used as an I/O pin.
AT90CAN32/64/128 Table 9-19 and Table 9-20 relates the alternate functions of Port F to the overriding signals shown in Figure 9-5 on page 72. Table 9-19. Overriding Signals for Alternate Functions in PF7..
9.3.8 Alternate Functions of Port G The alternate pin configuration is as follows: Table 9-21. Port Pin Port G Pins Alternate Functions Alternate Function PG4 TOSC1 (RTC Oscillator Timer/Counter2) PG3 TOSC2 (RTC Oscillator Timer/Counter2) PG2 ALE (Address Latch Enable to external memory) PG1 RD (Read strobe to external memory) PG0 WR (Write strobe to external memory) The alternate pin configuration is as follows: • TOSC1 – Port G, Bit 4 TOSC2, Timer/Counter2 Oscillator pin 1.
AT90CAN32/64/128 Table 9-21 and Table 9-22 relates the alternate functions of Port G to the overriding signals shown in Figure 9-5 on page 72. Table 9-22. Overriding Signals for Alternate Function in PG4 Signal Name 9.4.1 - - PG4/TOSC1 PUOE AS2 PUOV 0 DDOE AS2 DDOV 0 PVOE 0 PVOV 0 PTOE 0 DIEOE AS2 DIEOV EXCLK DI – AIO T/C2 OSC INPUT Table 9-23. 9.
9.4.2 Port A Data Direction Register – DDRA Bit 9.4.3 7 6 5 4 3 2 1 0 DDA7 DDA6 DDA5 DDA4 DDA3 DDA2 DDA1 DDA0 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 Port A Input Pins Address – PINA Bit 9.4.
AT90CAN32/64/128 9.4.10 Port D Data Register – PORTD Bit 9.4.11 7 6 5 4 3 2 1 0 PORTD7 PORTD6 PORTD5 PORTD4 PORTD3 PORTD2 PORTD1 PORTD0 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 Port D Data Direction Register – DDRD Bit 9.4.
9.4.18 Port F Input Pins Address – PINF Bit 9.4.19 7 6 5 4 3 2 1 0 PINF7 PINF6 PINF5 PINF4 PINF3 PINF2 PINF1 PINF0 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 Port G Data Register – PORTG Bit 9.4.
AT90CAN32/64/128 10. External Interrupts The External Interrupts are triggered by the INT7:0 pins. Observe that, if enabled, the interrupts will trigger even if the INT7:0 pins are configured as outputs. This feature provides a way of generating a software interrupt. The External Interrupts can be triggered by a falling or rising edge or a low level. This is set up as indicated in the specification for the External Interrupt Control Registers – EICRA (INT3:0) and EICRB (INT7:4).
Asynchronous External Interrupt Sense Control(1) Table 10-1. ISCn1 ISCn0 0 0 The low level of INTn generates an interrupt request. 0 1 Any logical change on INTn generates 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. Note: 1. n = 3, 2, 1 or 0.
AT90CAN32/64/128 10.1.3 External Interrupt Mask Register – EIMSK Bit 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 IINT0 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 EIMSK • Bits 7..0 – INT7 – INT0: External Interrupt Request 7 - 0 Enable When an INT7 – INT0 bit is written to one and the I-bit in the Status Register (SREG) is set (one), the corresponding external pin interrupt is enabled.
11. Timer/Counter3/1/0 Prescalers Timer/Counter3, Timer/Counter1 and Timer/Counter0 share the same prescaler module, but the Timer/Counters can have different prescaler settings. The description below applies to both Timer/Counter3, Timer/Counter1 and Timer/Counter0. 11.1 Overview Most bit references in this section are written in general form. A lower case “n” replaces the Timer/Counter number. 11.1.
AT90CAN32/64/128 Figure 11-1. T3/T1/T0 Pin Sampling D Tn Q D Q D Tn_sync (To Clock Select Logic) Q LE clk I/O Synchronization Edge Detector The synchronization and edge detector logic introduces a delay of 2.5 to 3.5 system clock cycles from an edge has been applied to the T3/T1/T0 pin to the counter is updated.
11.2 11.2.1 Timer/Counter0/1/3 Prescalers Register Description General Timer/Counter Control Register – GTCCR Bit 7 6 5 4 3 2 1 0 TSM – – – – – PSR2 PSR310 Read/Write R/W R R R R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 GTCCR • Bit 7 – TSM: Timer/Counter Synchronization Mode Writing the TSM bit to one activates the Timer/Counter Synchronization mode.
AT90CAN32/64/128 12. 8-bit Timer/Counter0 with PWM Timer/Counter0 is a general purpose, single channel, 8-bit Timer/Counter module. The main features are: 12.1 Features • • • • • • • 12.
12.2.1 Registers The Timer/Counter (TCNT0) and Output Compare Register (OCR0A) 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 Interrupt Mask Register (TIMSK0). TIFR0 and TIMSK0 are not shown in the figure. The Timer/Counter can be clocked internally, via the prescaler, or by an external clock source on the T0 pin.
AT90CAN32/64/128 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). clkTn Timer/Counter clock, referred to as clkT0 in the following. top Signalize that TCNT0 has reached maximum value. bottom Signalize that TCNT0 has reached minimum value (zero). Depending of the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clkT0).
Figure 12-3 shows a block diagram of the Output Compare unit. Figure 12-3. Output Compare Unit, Block Diagram DATA BUS OCRnx TCNTn = (8-bit Comparator ) OCFnx (Int.Req.) top bottom Waveform Generator OCnx FOCn WGMn1:0 COMnX1:0 The OCR0A 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.
AT90CAN32/64/128 generation. Similarly, do not write the TCNT0 value equal to BOTTOM when the counter is downcounting. The setup of the OC0A should be performed before setting the Data Direction Register for the port pin to output. The easiest way of setting the OC0A value is to use the Force Output Compare (FOC0A) strobe bits in Normal mode. The OC0A Register keeps its value even when changing between Waveform Generation modes.
12.6.2 Compare Output Mode and Waveform Generation The Waveform Generator uses the COM0A1:0 bits differently in Normal, CTC, and PWM modes. For all modes, setting the COM0A1:0 = 0 tells the Waveform Generator that no action on the OC0A Register is to be performed on the next compare match. For compare output actions in the non-PWM modes refer to Table 12-2 on page 110. For fast PWM mode, refer to Table 123 on page 110, and for phase correct PWM refer to Table 12-4 on page 111.
AT90CAN32/64/128 Figure 12-5. CTC Mode, Timing Diagram OCnx Interrupt Flag Set TCNTn OCnx (Toggle) Period (COMnx1:0 = 1) 1 2 3 4 An interrupt can be generated each time the counter value reaches the TOP value by using the OCF0A flag. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value.
inverted PWM outputs. The small horizontal line marks on the TCNT0 slopes represent compare matches between OCR0A and TCNT0. Figure 12-6. Fast PWM Mode, Timing Diagram OCRnx Interrupt Flag Set OCRnx Update and TOVn Interrupt Flag Set TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 5 6 7 The Timer/Counter Overflow Flag (TOV0) is set each time the counter reaches MAX. If the interrupt is enabled, the interrupt handler routine can be used for updating the compare value.
AT90CAN32/64/128 12.7.4 Phase Correct PWM Mode The phase correct PWM mode (WGM01:0 = 1) 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 MAX and then from MAX to BOTTOM. In noninverting Compare Output mode, the Output Compare (OC0A) is cleared on the compare match between TCNT0 and OCR0A while upcounting, and set on the compare match while downcounting.
decrements. The PWM frequency for the output when using phase correct PWM can be calculated by the following equation: f clk_I/O f OCnxPCPWM = -----------------N ⋅ 510 The N variable represents the prescale factor (1, 8, 64, 256, or 1024). The extreme values for the OCR0A Register represent special cases when generating a PWM waveform output in the phase correct PWM mode.
AT90CAN32/64/128 Figure 12-10 shows the setting of OCF0A in all modes except CTC mode. Figure 12-10. Timer/Counter Timing Diagram, Setting of OCF0A, with Prescaler (fclk_I/O/8) clkI/O clkTn (clkI/O /8) TCNTn OCRnx - 1 OCRnx OCRnx OCRnx + 1 OCRnx + 2 OCRnx Value OCFnx Figure 12-11 shows the setting of OCF0A and the clearing of TCNT0 in CTC mode. Figure 12-11.
• Bit 6, 3 – WGM01:0: Waveform Generation Mode These bits control the counting sequence of the counter, the source for the maximum (TOP) counter value, and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode, Clear Timer on Compare match (CTC) mode, and two types of Pulse Width Modulation (PWM) modes. See Table 12-1 and “Modes of Operation” on page 104. Table 12-1.
AT90CAN32/64/128 Note: 1. A special case occurs when OCR0A equals TOP and COM0A1 is set. In this case, the compare match is ignored, but the set or clear is done at TOP. See “Fast PWM Mode” on page 105 for more details. Table 12-4 shows the COM0A1:0 bit functionality when the WGM01:0 bits are set to phase correct PWM mode. Compare Output Mode, Phase Correct PWM Mode(1) Table 12-4. COM0A1 COM0A0 0 0 Normal port operation, OC0A disconnected.
12.9.3 Output Compare Register A – OCR0A Bit 7 6 5 4 3 2 1 0 OCR0A[7:0] OCR0 Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 The Output Compare Register A contains an 8-bit value that is continuously compared with the counter value (TCNT0). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC0A pin. 12.9.
AT90CAN32/64/128 13. 16-bit Timer/Counter (Timer/Counter1 and Timer/Counter3) The 16-bit Timer/Counter unit allows accurate program execution timing (event management), wave generation, and signal timing measurement. The main features are: 13.1 Features • • • • • • • • • • • 13.2 True 16-bit Design (i.e.
Figure 13-1. 16-bit Timer/Counter Block Diagram(1) Count Clear Direction TOVn (Int.Req.) Control Logic clk Tn Clock Select Edge Detector TOP Tn BOTTOM ( From Prescaler ) Timer/Counter TCNTn = =0 OCFnA (Int.Req.) Waveform Generation = OCnA OCRnA OCFnB (Int.Req.) Fixed TOP Values Waveform Generation DATABUS = OCnB OCRnB OCFnC (Int.Req.) Waveform Generation = OCRnC OCnC ( From Analog Comparator Ouput ) ICFn (Int.Req.) Edge Detector ICRn Noise Canceler ICPn TCCRnA Note: 13.2.
AT90CAN32/64/128 uses to increment (or decrement) its value. The Timer/Counter is inactive when no clock source is selected. The output from the Clock Select logic is referred to as the timer clock (clkTn). The double buffered Output Compare Registers (OCRnx) are compared with the Timer/Counter value at all time. The result of the compare can be used by the Waveform Generator to generate a PWM or variable frequency output on the Output Compare pin (OCnx). See “Output Compare Units” on page 123..
The 16-bit Timer/Counter has improvements that will affect the compatibility in some special cases. The following bits are added to the 16-bit Timer/Counter Control Registers: • COMnC1:0 are added to TCCRnA. • FOCnA, FOCnB and FOCnC are added to TCCRnC. • WGMn3 is added to TCCRnB. Interrupt flag and mask bits for output compare unit C are added. The 16-bit Timer/Counter has improvements that will affect the compatibility in some special cases. 13.
AT90CAN32/64/128 13.3.1 Code Examples 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 OCRnx and ICRn Registers. Note that when using “C”, the compiler handles the 16-bit access. Assembly Code Examples(1) ... ; Set TCNTn to 0x01FF ldi r17,0x01 ldi r16,0xFF sts TCNTnH,r17 sts TCNTnL,r16 ; Read TCNTn into r17:r16 lds r16,TCNTnL lds r17,TCNTnH ...
The following code examples show how to do an atomic read of the TCNTn Register contents. Reading any of the OCRnx or ICRn Registers can be done by using the same principle.
AT90CAN32/64/128 The following code examples show how to do an atomic write of the TCNTn Register contents. Writing any of the OCRnx or ICRn Registers can be done by using the same principle.
13.5 Counter Unit The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit. Figure 13-2 shows a block diagram of the counter and its surroundings. Figure 13-2. Counter Unit Block Diagram DATA BUS (8-bit) TOVn (Int.Req.
AT90CAN32/64/128 The Timer/Counter Overflow Flag (TOVn) is set according to the mode of operation selected by the WGMn3:0 bits. TOVn can be used for generating a CPU interrupt. 13.6 Input Capture Unit The Timer/Counter incorporates an Input Capture unit that can capture external events and give them a time-stamp indicating time of occurrence. The external signal indicating an event, or multiple events, can be applied via the ICPn pin or alternatively, via the analog-comparator unit.
cleared when the interrupt is executed. Alternatively the ICFn flag can be cleared by software by writing a logical one to its I/O bit location. Reading the 16-bit value in the Input Capture Register (ICRn) is done by first reading the low byte (ICRnL) and then the high byte (ICRnH). When the low byte is read the high byte is copied into the high byte temporary register (TEMP). When the CPU reads the ICRnH I/O location it will access the TEMP Register.
AT90CAN32/64/128 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.
Figure 13-4. Output Compare Unit, Block Diagram DATA BUS (8-bit) TEMP (8-bit) OCRnxH Buf.(8-bit) OCRnxL Buf.(8-bit) TCNTnH (8-bit) OCRnx Buffer (16-bit Register) OCRnxH (8-bit) TCNTnL (8-bit) TCNTn (16-bit Counter) OCRnxL (8-bit) OCRnx (16-bit Register) = (16-bit Comparator ) OCFnx TOP BOTTOM Waveform Generator WGMn3:0 (Int.Req.) OCnx COMnx1:0 The OCRnx Register is double buffered when using any of the twelve Pulse Width Modulation (PWM) modes.
AT90CAN32/64/128 match had occurred (the COMnx1:0 bits settings define whether the OCnx pin is set, cleared or toggled). 13.7.2 Compare Match Blocking by TCNTn Write All CPU writes to the TCNTn Register will block any compare match that occurs in the next timer clock cycle, even when the timer is stopped. This feature allows OCRnx to be initialized to the same value as TCNTn without triggering an interrupt when the Timer/Counter clock is enabled. 13.7.
Figure 13-5. Compare Match Output Unit, Schematic COMnx1 COMnx0 FOCnx Waveform Generator D Q 1 OCnx DATA BUS D 0 OCnx Pin Q PORT D Q DDR clk I/O 13.8.1 Compare Output Function The general I/O port function is overridden by the Output Compare (OCnx) from the Waveform Generator if either of the COMnx1:0 bits are set. However, the OCnx pin direction (input or output) is still controlled by the Data Direction Register (DDR) for the port pin.
AT90CAN32/64/128 while the Waveform Generation mode bits do. The COMnx1:0 bits control whether the PWM output generated should be inverted or not (inverted or non-inverted PWM). For non-PWM modes the COMnx1:0 bits control whether the output should be set, cleared or toggle at a compare match (See “Compare Match Output Unit” on page 125.) For detailed timing information refer to “Timer/Counter Timing Diagrams” on page 134. 13.9.1 Normal Mode The simplest mode of operation is the Normal mode (WGMn3:0 = 0).
An interrupt can be generated at each time the counter value reaches the TOP value by either using the OCFnA or ICFn flag according to the register used to define the TOP value. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value. However, changing the TOP to a value close to BOTTOM when the counter is running with none or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature.
AT90CAN32/64/128 shows fast PWM mode when OCRnA or ICRn is used to define TOP. The TCNTn value is in the timing diagram shown as a histogram for illustrating the single-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNTn slopes represent compare matches between OCRnx and TCNTn. The OCnx interrupt flag will be set when a compare match occurs. Figure 13-7.
In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COMnx1:0 to three (see Table on page 136). The actual OCnx value will only be visible on the port pin if the data direction for the port pin is set as output (DDR_OCnx).
AT90CAN32/64/128 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNTn slopes represent compare matches between OCRnx and TCNTn. The OCnx interrupt flag will be set when a compare match occurs. Figure 13-8.
output (DDR_OCnx). The PWM waveform is generated by setting (or clearing) the OCnx Register at the compare match between OCRnx and TCNTn when the counter increments, and clearing (or setting) the OCnx Register at compare match between OCRnx and TCNTn when the counter decrements.
AT90CAN32/64/128 Figure 13-9. Phase and Frequency Correct PWM Mode, Timing Diagram OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) OCRnx/TOP Update and TOVn Interrupt Flag Set (Interrupt on Bottom) TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 The Timer/Counter Overflow Flag (TOVn) is set at the same timer clock cycle as the OCRnx Registers are updated with the double buffer value (at BOTTOM).
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024). The extreme values for the OCRnx Register represents special cases when generating a PWM waveform output in the phase correct PWM mode. If the OCRnx is set equal to BOTTOM the output will be continuously low and if set equal to TOP the output will be set to high for noninverted PWM mode. For inverted PWM the output will have the opposite logic values. 13.
AT90CAN32/64/128 Figure 13-12. Timer/Counter Timing Diagram, no Prescaling clkI/O clkTn (clkI/O /1) TCNTn (CTC and FPWM) TCNTn (PC and PFC PWM) TOP - 1 TOP BOTTOM TOP - 1 TOP TOP - 1 BOTTOM + 1 TOP - 2 TOVn (FPWM) and ICFn (if used as TOP) OCRnx New OCRnx Value Old OCRnx Value (Update at TOP) Figure 13-13 shows the same timing data, but with the prescaler enabled. Figure 13-13.
• Bit 7:6 – COMnA1:0: Compare Output Mode for Channel A • Bit 5:4 – COMnB1:0: Compare Output Mode for Channel B • Bit 3:2 – COMnC1:0: Compare Output Mode for Channel C The COMnA1:0, COMnB1:0 and COMnC1:0 control the Output Compare pins (OCnA, OCnB and OCnC respectively) behavior. If one or both of the COMnA1:0 bits are written to one, the OCnA output overrides the normal port functionality of the I/O pin it is connected to.
AT90CAN32/64/128 Table 13-3 shows the COMnx1:0 bit functionality when the WGMn3:0 bits are set to the phase correct or the phase and frequency correct, PWM mode. Table 13-3. Compare Output Mode, Phase Correct and Phase and Frequency Correct PWM(1) COMnA1/COMnB1/ COMnC1 COMnA0/COMnB0/ COMnC0 0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 1 WGMn3=0: Normal port operation, OCnA/OCnB/OCnC disconnected. WGMn3=1: Toggle OCnA on Compare Match, OCnB/OCnC reserved.
Waveform Generation Mode Bit Description (1) Table 13-4.
AT90CAN32/64/128 This bit selects which edge on the Input Capture pin (ICPn) 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 (ICRn).
13.11.6 Timer/Counter3 Control Register C – TCCR3C Bit 7 6 5 4 3 2 1 0 FOC3A FOC3B FOC3C – – – – – Read/Write R/W R/W R/W R R R R R Initial Value 0 0 0 0 0 0 0 0 TCCR3C • Bit 7 – FOCnA: Force Output Compare for Channel A • Bit 6 – FOCnB: Force Output Compare for Channel B • Bit 5 – FOCnC: Force Output Compare for Channel C The FOCnA/FOCnB/FOCnC bits are only active when the WGMn3:0 bits specifies a non-PWM mode.
AT90CAN32/64/128 13.11.9 Output Compare Register A – OCR1AH and OCR1AL Bit 7 6 5 4 3 2 1 0 OCR1A[15:8] OCR1AH OCR1A[7:0] OCR1AL Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 4 3 2 1 0 13.11.10 Output Compare Register B – OCR1BH and OCR1BL Bit 7 6 5 OCR1B[15:8] OCR1BH OCR1B[7:0] OCR1BL Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 4 3 2 1 0 13.11.
13.11.15 Input Capture Register – ICR1H and ICR1L Bit 7 6 5 4 3 2 1 0 ICR1[15:8] ICR1H ICR1[7:0] ICR1L Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 5 4 3 2 1 0 13.11.
AT90CAN32/64/128 • Bit 2 – OCIEnB: 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/Countern Output Compare B Match interrupt is enabled. The corresponding Interrupt Vector (See “Interrupts” on page 60.) is executed when the OCFnB flag, located in TIFRn, is set.
• Bit 2 – OCFnB: Output Compare B Match Flag This flag is set in the timer clock cycle after the counter (TCNTn) value matches the Output Compare Register B (OCRnB). Note that a Forced Output Compare (FOCnB) strobe will not set the OCFnB flag. OCFnB is automatically cleared when the Output Compare Match B Interrupt Vector is executed. Alternatively, OCFnB can be cleared by writing a logic one to its bit location.
AT90CAN32/64/128 14. 8-bit Timer/Counter2 with PWM and Asynchronous Operation Timer/Counter2 is a general purpose, single channel, 8-bit Timer/Counter module. The main features are: 14.1 Features • • • • • • • 14.
Figure 14-1. 8-bit Timer/Counter2 Block Diagram TCCRnx count TOVn (Int.Req.) clear Control Logic direction clkTn TOSC2 BOTTOM TOP Prescaler T/C Oscillator TOSC1 Timer/Counter TCNTn =0 = 0xFF DATA BUS OCnx (Int.Req.) Waveform Generation = clk I/O OCnx OCRnx Synchronized Status flags clk I/O Synchronization Unit clk ASY Status flags ASSRn asynchronous mode select (ASn) The Timer/Counter (TCNT2) and Output Compare Register (OCR2A) are 8-bit registers. Interrupt request (shorten as Int.
AT90CAN32/64/128 14.2.1 Definitions The following definitions are used extensively throughout the section: 14.3 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.
Depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clkT2). clkT2 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 clkT2 is present or not. A CPU write overrides (has priority over) all counter clear or count operations.
AT90CAN32/64/128 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 OCR2A Register access may seem complex, but this is not case. When the double buffering is enabled, the CPU has access to the OCR2A Buffer Register, and if double buffering is disabled the CPU will access the OCR2A directly. 14.5.
Figure 14-5. Compare Match Output Unit, Schematic COMnx1 COMnx0 FOCnx Waveform Generator D Q 1 OCnx DATA BUS D 0 OCnx Pin Q PORT D Q DDR clk I/O 14.6.1 Compare Output Function The general I/O port function is overridden by the Output Compare (OC2A) from the Waveform Generator if either of the COM2A1:0 bits are set. However, the OC2A pin direction (input or output) is still controlled by the Data Direction Register (DDR) for the port pin.
AT90CAN32/64/128 For detailed timing information refer to “Timer/Counter Timing Diagrams” on page 155. 14.7.1 Normal Mode The simplest mode of operation is the Normal mode (WGM21:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum 8-bit value (TOP = 0xFF) and then restarts from the bottom (0x00).
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 fOC2A = fclk_I/O/2 when OCR2A is set to zero (0x00).
AT90CAN32/64/128 The Timer/Counter Overflow Flag (TOV2) is set each time the counter reaches MAX. If the interrupt is enabled, the interrupt handler routine can be used for updating the compare value. In fast PWM mode, the compare unit allows generation of PWM waveforms on the OC2A pin. Setting the COM2A1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM2A1:0 to three (See Table 14-3 on page 158).
Figure 14-8. Phase Correct PWM Mode, Timing Diagram OCnx Interrupt Flag Set OCRnx Update TOVn Interrupt Flag Set TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 The Timer/Counter Overflow Flag (TOV2) is set each time the counter reaches BOTTOM. The interrupt flag can be used to generate an interrupt each time the counter reaches the BOTTOM value. In phase correct PWM mode, the compare unit allows generation of PWM waveforms on the OC2A pin.
AT90CAN32/64/128 match. To ensure symmetry around BOTTOM the OCn value at MAX must correspond to the result of an up-counting Compare Match. • The timer starts counting from a value higher than the one in OCR2A, and for that reason misses the Compare Match and hence the OCn change that would have happened on the way up. 14.8 Timer/Counter Timing Diagrams The following figures show the Timer/Counter in synchronous mode, and the timer clock (clkT2) is therefore shown as a clock enable signal.
Figure 14-11.
AT90CAN32/64/128 Figure 14-12 shows the setting of OCF2A and the clearing of TCNT2 in CTC mode. Figure 14-12. Timer/Counter Timing Diagram, Clear Timer on Compare Match mode, with Prescaler (fclk_I/O/8) clkI/O clkTn (clkI/O /8) TCNTn (CTC) TOP - 1 TOP OCRnx BOTTOM BOTTOM + 1 TOP OCFnx 14.9 8-bit Timer/Counter Register Description 14.9.
two types of Pulse Width Modulation (PWM) modes. See Table 14-1 and “Modes of Operation” on page 150. Table 14-1. Waveform Generation Mode Bit Description(1) Mode WGM21 (CTC2) WGM20 (PWM2) Timer/Counter Mode of Operation TOP Update of OCR2A at TOV2 Flag Set on 0 0 0 Normal 0xFF Immediate MAX 1 0 1 PWM, Phase Correct 0xFF TOP BOTTOM 2 1 0 CTC OCR2A Immediate MAX 3 1 1 Fast PWM 0xFF TOP MAX Note: 1. The CTC2 and PWM2 bit definition names are now obsolete.
AT90CAN32/64/128 Table 14-4 shows the COM21:0 bit functionality when the WGM21:0 bits are set to phase correct PWM mode. Table 14-4. Compare Output Mode, Phase Correct PWM Mode(1) COM2A1 COM2A0 0 0 Normal port operation, OC2A disconnected. 0 1 Reserved 1 0 Clear OC2A on compare match when up-counting. Set OC2A on compare match when downcounting. 1 1 Set OC2A on compare match when up-counting. Clear OC2A on compare match when downcounting. Note: Description 1.
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. 14.10 Asynchronous operation of the Timer/Counter2 14.10.1 Asynchronous Status Register – ASSR Bit 7 6 5 4 3 2 1 0 – – – EXCLK AS2 TCN2UB OCR2UB TCR2UB Read/Write R R R R/W R/W R R R Initial Value 0 0 0 0 0 0 0 0 ASSR • Bit 7..
AT90CAN32/64/128 14.10.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, OCR2A, and TCCR2A might be corrupted. A safe procedure for switching clock source is: a. Disable the Timer/Counter2 interrupts by clearing OCIE2A and TOIE2. b. Select clock source by setting AS2 and EXCLK as appropriate. c.
• Description of wake up from Power-save 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.
AT90CAN32/64/128 • Bit 7..2 – Reserved Bits These bits are reserved for future use. • Bit 1 – OCF2A: Output Compare Flag 2 A The OCF2A bit is set (one) when a compare match occurs between the Timer/Counter2 and the data in OCR2A – Output Compare Register2. OCF2A is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF2A is cleared by writing a logic one to the flag.
Figure 14-14. Timer/Counter2 Crystal Oscillator Connections 12 - 22 pF TOSC2 32.768 KHz TOSC1 12 - 22 pF GND A external clock can also be used using TOSC1 as input. Setting AS2 and EXCLK enables this configuration. Figure 14-15. Timer/Counter2 External Clock Connections NC TOSC2 External Clock Signal TOSC1 For Timer/Counter2, the possible prescaled selections are: clk T2S /8, clk T2S /32, clk T2S /64, clkT2S/128, clkT2S/256, and clkT2S/1024. Additionally, clkT2S as well as 0 (stop) may be selected.
AT90CAN32/64/128 15. Output Compare Modulator - OCM 15.1 Overview Many register and bit references in this section are written in general form. • A lower case “n” replaces the Timer/Counter number, in this case 0 and 1. However, when using the register or bit defines in a program, the precise form must be used, i.e., TCNT0 for accessing Timer/Counter0 counter value and so on. • A lower case “x” replaces the Output Compare unit channel, in this case A or C.
Figure 15-2. Output Compare Modulator, Schematic COM0A1 COM0A0 Vcc COM1C1 COM1C0 (From T/C1 Waveform Generator) Modulator 0 D 1 Q 1 OC1C Pin 0 (From T/C0 Waveform Generator) D OC0A / OC1C / PB7 Q OC0A D Q D PORTB7 Q DDRB7 DATABUS 15.2.1 Timing Example Figure 15-3 illustrates the modulator in action. In this example the Timer/Counter1 is set to operate in fast PWM mode (non-inverted) and Timer/Counter0 uses CTC waveform mode with toggle Compare Output mode (COMnx1:0 = 1). Figure 15-3.
AT90CAN32/64/128 15.2.2 Resolution of the PWM Signal The resolution of the PWM signal (OC1C) is reduced by the modulation. The reduction factor is equal to the number of system clock cycles of one period of the carrier (OC0A). In this example the resolution is reduced by a factor of two. The reason for the reduction is illustrated in Figure 15-3 at the second and third period of the PB7 output when PORTB7 equals zero.
16. Serial Peripheral Interface – SPI The Serial Peripheral Interface (SPI) allows high-speed synchronous data transfer between the AT90CAN32/64/128 and peripheral devices or between several AVR devices. The AT90CAN32/64/128 SPI includes the following features: 16.
AT90CAN32/64/128 The interconnection between Master and Slave CPUs with SPI is shown in Figure 16-2. The system 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.
When the SPI is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden according to Table 16-1. For more details on automatic port overrides, refer to “Alternate Port Functions” on page 71. Table 16-1. Pin Direction, Master SPI Direction, Slave SPI MOSI User Defined Input MISO Input User Defined SCK User Defined Input SS User Defined Input Note: 170 SPI Pin Overrides(1) 1.
AT90CAN32/64/128 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 PB2, replace DD_MOSI with DDB2 and DDR_SPI with DDRB.
The following code examples show how to initialize the SPI as a Slave and how to perform a simple reception.
AT90CAN32/64/128 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. 16.2.
and SPIF in SPSR will become set. The user will then have to set MSTR to re-enable SPI Master mode. • Bit 3 – CPOL: Clock Polarity When this bit is written to one, SCK is high when idle. When CPOL is written to zero, SCK is low when idle. Refer to Figure 16-3 and Figure 16-4 for an example. The CPOL functionality is summarized below: Table 16-2.
AT90CAN32/64/128 16.2.4 SPI Status Register – SPSR Bit 7 6 5 4 3 2 1 0 SPIF WCOL – – – – – SPI2X Read/Write R R R R R R R R/W Initial Value 0 0 0 0 0 0 0 0 SPSR • 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.
nal, ensuring sufficient time for data signals to stabilize. This is clearly seen by summarizing Table 16-2 and Table 16-3, as done below: Table 16-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 Figure 16-3.
AT90CAN32/64/128 17. USART (USART0 and USART1) The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly flexible serial communication device. The main features are: 17.1 Features • • • • • • • • • • • • 17.
Figure 17-1. USARTn Block Diagram (1) Clock Generator UBRRn[H:L] CLKio BAUD RATE GENERATOR SYNC LOGIC PIN CONTROL XCKn Transmitter TX CONTROL DATA BUS UDRn (Transmit) PARITY GENERATOR TxDn Receiver RECEIVE SHIFT REGISTER UDRn (Receive) UCSRAn Note: PIN CONTROL TRANSMIT SHIFT REGISTER CLOCK RECOVERY RX CONTROL DATA RECOVERY PIN CONTROL RxDn PARITY CHECKER UCSRBn UCSRCn 1.
AT90CAN32/64/128 17.4 Clock Generation The Clock Generation logic generates the base clock for the Transmitter and Receiver. The USARTn supports four modes of clock operation: Normal asynchronous, Double Speed asynchronous, Master synchronous and Slave synchronous mode. The UMSELn bit in USARTn Control and Status Register C (UCSRnC) selects between asynchronous and synchronous operation. Double Speed (asynchronous mode only) is controlled by the U2Xn found in the UCSRnA Register.
units use a state machine that uses 2, 8 or 16 states depending on mode set by the state of the UMSELn, U2Xn and DDR_XCKn bits. Table 17-1 contains equations for calculating the baud rate (in bits per second) and for calculating the UBRRn value for each mode of operation using an internally generated clock source. Table 17-1.
AT90CAN32/64/128 Note that fclkio depends on the stability of the system clock source. It is therefore recommended to add some margin to avoid possible loss of data due to frequency variations. 17.4.4 Synchronous Clock Operation When synchronous mode is used (UMSELn = 1), the XCKn pin will be used as either clock input (Slave) or clock output (Master). The dependency between the clock edges and data sampling or data change is the same.
Figure 17-4. Frame Formats FRAME (IDLE) St 0 1 2 3 4 [5] [6] [7] [8] [P] Sp1 [Sp2] St Start bit, always low. (n) Data bits (0 to 8). P Parity bit. Can be odd or even. Sp Stop bit, always high. IDLE No transfers on the communication line (RxDn or TxDn). An IDLE line must be high. (St / IDLE) The frame format used by the USARTn is set by the UCSZn2:0, UPMn1:0 and USBSn bits in UCSRnB and UCSRnC. The Receiver and Transmitter use the same setting.
AT90CAN32/64/128 check that there are no unread data in the receive buffer. Note that the TXCn flag must be cleared before each transmission (before UDRn is written) if it is used for this purpose. The following simple USART0 initialization code examples show one assembly and one C function that are equal in functionality. The examples assume asynchronous operation using polling (no interrupts enabled) and a fixed frame format. The baud rate is given as a function parameter.
chronous operation is used, the clock on the XCKn pin will be overridden and used as transmission clock. 17.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 UDRn I/O location. The buffered data in the transmit buffer will be moved to the Shift Register when the Shift Register is ready to send a new frame.
AT90CAN32/64/128 17.7.2 Sending Frames with 9 Data Bit If 9-bit characters are used (UCSZn = 7), the ninth bit must be written to the TXB8n bit in UCSRnB before the low byte of the character is written to UDRn. The following code examples show a transmit function that handles 9-bit characters. For the assembly code, the data to be sent is assumed to be stored in registers R17:R16.
The Data Register Empty (UDREn) 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 yet been moved into the Shift Register. For compatibility with future devices, always write this bit to zero when writing the UCSRnA Register.
AT90CAN32/64/128 The following code example shows a simple USART0 receive function based on polling of the Receive Complete (RXC0) flag. When using frames with less than eight bits the most significant bits of the data read from the UDR0 will be masked to zero. The USART0 has to be initialized before the function can be used.
The following code example shows a simple USART0 receive function that handles both nine bit characters and the status bits.
AT90CAN32/64/128 17.8.3 Receive Complete Flag and Interrupt The USARTn Receiver has one flag that indicates the Receiver state. The Receive Complete (RXCn) flag indicates if there are unread data present in the receive buffer. 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 (RXENn = 0), the receive buffer will be flushed and consequently the RXCn bit will become zero.
The UPEn 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 (UPMn1 = 1). This bit is valid until the receive buffer (UDRn) is read. 17.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.
AT90CAN32/64/128 izontal arrows illustrate the synchronization variation due to the sampling process. Note the larger time variation when using the Double Speed mode (U2Xn = 1) of operation. Samples denoted zero are samples done when the RxDn line is idle (i.e., no communication activity). Figure 17-5.
Figure 17-7 shows the sampling of the stop bit and the earliest possible beginning of the start bit of the next frame. Figure 17-7. Stop Bit Sampling and Next Start Bit Sampling RxDn STOP 1 (A) (B) (C) Sample (U2Xn = 0) 1 2 3 4 5 6 7 8 9 10 0/1 0/1 0/1 Sample (U2Xn = 1) 1 2 3 4 5 6 0/1 The same majority voting is done to the stop bit as done for the other bits in the frame. If the stop bit is registered to have a logic 0 value, the Frame Error (FEn) flag will be set.
AT90CAN32/64/128 Table 17-2. Recommended Maximum Receiver Baud Rate Error for Normal Speed Mode (U2Xn = 0) D # (Data + Parity Bit) Rslow (%) Rfast (%) 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 17-3.
17.10.1 MPCM Protocol If the Receiver is set up to receive frames that contain 5 to 8 data bits, then the first stop bit indicates if the frame contains data or address information. If the Receiver is set up for frames with nine data bits, then the ninth bit (RXB8n) is used for identifying address and data frames. When the frame type bit (the first stop or the ninth bit) is one, the frame contains an address. When the frame type bit is zero the frame is a data frame.
AT90CAN32/64/128 17.11 USART Register Description 17.11.1 USART0 I/O Data Register – UDR0 Bit 17.11.
• Bit 6 – TXCn: USARTn 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 (UDRn). The TXCn 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 TXCn flag can generate a Transmit Complete interrupt (see description of the TXCIEn bit).
AT90CAN32/64/128 17.11.6 USART1 Control and Status Register B – UCSR1B Bit 7 6 5 4 3 2 1 0 RXCIE1 TXCIE1 UDRIE1 RXEN1 TXEN1 UCSZ12 RXB81 TXB81 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 UCSR1B • Bit 7 – RXCIEn: RX Complete Interrupt Enable Writing this bit to one enables interrupt on the RXCn flag.
17.11.8 USART1 Control and Status Register C – UCSR1C Bit 7 6 5 4 3 2 1 0 – UMSEL1 UPM11 UPM10 USBS1 UCSZ11 UCSZ10 UCPO1L Read/Write R R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 1 1 0 UCSR1C • Bit 7 – Reserved Bit This bit is reserved for future use. For compatibility with future devices, these bit must be written to zero when UCSRnC is written. • Bit 6 – UMSELn: USARTn Mode Select This bit selects between asynchronous and synchronous mode of operation.
AT90CAN32/64/128 • Bit 2:1 – UCSZn1:0: Character Size The UCSZn1:0 bits combined with the UCSZn2 bit in UCSRnB sets the number of data bits (Character SiZe) in a frame the Receiver and Transmitter use. Table 17-7. UCSZn Bits Settings UCSZn2 UCSZn1 UCSZn0 Character Size 0 0 0 5-bit 0 0 1 6-bit 0 1 0 7-bit 0 1 1 8-bit 1 0 0 Reserved 1 0 1 Reserved 1 1 0 Reserved 1 1 1 9-bit • Bit 0 – UCPOLn: Clock Polarity This bit is used for synchronous mode only.
• Bit 15:12 – Reserved Bits These bits are reserved for future use. For compatibility with future devices, these bit must be written to zero when UBRRnH is written. • Bit 11:0 – UBRRn11:0: USARTn Baud Rate Register This is a 12-bit register which contains the USARTn baud rate. The UBRRnH contains the four most significant bits, and the UBRRnL contains the eight least significant bits of the USARTn baud rate. Ongoing transmissions by the Transmitter and Receiver will be corrupted if the baud rate is changed.
AT90CAN32/64/128 Table 17-10. Examples of UBRRn Settings for Commonly Frequencies (Continued) Baud Rate (bps) fclkio = 3.6864 MHz U2Xn = 0 UBRRn fclkio = 4.0000 MHz U2Xn = 1 Error UBRRn U2Xn = 0 Error UBRRn fclkio = 7.3728 MHz U2Xn = 1 Error UBRRn U2Xn = 0 Error UBRRn U2Xn = 1 Error UBRRn Error 2400 95 0.0% 191 0.0% 103 0.2% 207 0.2% 191 0.0% 383 0.0% 4800 47 0.0% 95 0.0% 51 0.2% 103 0.2% 95 0.0% 191 0.0% 9600 23 0.0% 47 0.0% 25 0.2% 51 0.2% 47 0.0% 95 0.
Table 17-11. Examples of UBRRn Settings for Commonly Frequencies (Continued) Baud Rate (bps) fclkio = 8.0000 MHz U2Xn = 0 UBRRn Error fclkio = 10.000 MHz U2Xn = 1 UBRRn Error U2Xn = 0 UBRRn Error fclkio = 11.0592 MHz U2Xn = 1 UBRRn Error U2Xn = 0 UBRRn Error U2Xn = 1 UBRRn Error 2400 207 0.2% 416 -0.1% 259 0.2% 520 0.0% 287 0.0% 575 0.0% 4800 103 0.2% 207 0.2% 129 0.2% 259 0.2% 143 0.0% 287 0.0% 9600 51 0.2% 103 0.2% 64 0.2% 129 0.2% 71 0.0% 143 0.0% 14.
AT90CAN32/64/128 Table 17-12. Examples of UBRRn Settings for Commonly Frequencies (Continued) Baud Rate (bps) fclkio = 12.0000 MHz U2Xn = 0 UBRRn Error fclkio = 14.7456 MHz U2Xn = 1 UBRRn Error U2Xn = 0 UBRRn Error fclkio = 16.0000 MHz U2Xn = 1 UBRRn Error U2Xn = 0 UBRRn Error U2Xn = 1 UBRRn Error 2400 312 -0.2% 624 0.0% 383 0.0% 767 0.0% 416 -0.1% 832 0.0% 4800 155 0.2% 312 -0.2% 191 0.0% 383 0.0% 207 0.2% 416 -0.1% 9600 77 0.2% 155 0.2% 95 0.0% 191 0.
18. Two-wire Serial Interface 18.1 Features • • • • • • • • • • 18.
AT90CAN32/64/128 18.2.2 Electrical Interconnection As depicted in Figure 18-1, both bus lines are connected to the positive supply voltage through pull-up resistors. The bus drivers of all TWI-compliant devices are open-drain or open-collector. This implements a wired-AND function which is essential to the operation of the interface. A low level on a TWI bus line is generated when one or more TWI devices output a zero.
Figure 18-3. START, REPEATED START and STOP Conditions SDA SCL START 18.3.3 REPEATED START STOP START STOP Address Packet Format All address packets transmitted on the TWI bus are 9 bits long, consisting of 7 address bits, one READ/WRITE control bit and an acknowledge bit. If the READ/WRITE bit is set, a read operation is to be performed, otherwise a write operation should be performed.
AT90CAN32/64/128 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 18-5.
• 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.
AT90CAN32/64/128 Figure 18-8. Arbitration Between two Masters START SDA from Master A Master A loses Arbitration, SDAA SDA SDA from Master B SDA Line Synchronized SCL Line 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.
Figure 18-9. Overview of the TWI Module SCL Slew-rate Control SDA Spike Filter Spike Filter Slew-rate Control Bus Interface Unit START / STOP Control Spike Suppression Arbitration detection Address/Data Shift Register (TWDR) Bit Rate Generator Prescaler Address Match Unit Address Register (TWAR) Bit Rate Register (TWBR) Ack Control Unit Status Register (TWSR) Address Comparator Control Register (TWCR) State Machine and Status control TWI Unit 18.5.
AT90CAN32/64/128 18.5.3 Bus Interface Unit This unit contains the Data and Address Shift Register (TWDR), a START/STOP Controller and Arbitration detection hardware. The TWDR contains the address or data bytes to be transmitted, or the address or data bytes received. In addition to the 8-bit TWDR, the Bus Interface Unit also contains a register containing the (N)ACK bit to be transmitted or received. This (N)ACK Register is not directly accessible by the application software.
• When a bus error has occurred due to an illegal START or STOP condition 18.6 18.6.1 TWI Register Description TWI Bit Rate Register – TWBR Bit 7 6 5 4 3 2 1 0 TWBR7 TWBR6 TWBR5 TWBR4 TWBR3 TWBR2 TWBR1 TWBR0 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 TWBR • Bits 7.0 – TWI Bit Rate Register TWBR selects the division factor for the bit rate generator.
AT90CAN32/64/128 The application writes the TWSTA bit to one when it desires to become a master on the Twowire 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.
• Bits 1.0 – TWPS: TWI Prescaler Bits These bits can be read and written, and control the bit rate prescaler. Table 18-2. TWI Bit Rate Prescaler TWPS1 TWPS0 Prescaler Value 0 0 1 0 1 4 1 0 16 1 1 64 To calculate bit rates, see “Bit Rate Generator Unit” on page 210. The value of TWPS1.0 is used in the equation. 18.6.
AT90CAN32/64/128 TWGCE 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. If set, this bit enables the recognition of a General Call given over the TWI Serial Bus. 18.7 Using the TWI The AVR TWI is byte-oriented and interrupt based.
the application has cleared TWINT, the TWI will initiate transmission of the START condition. 2. When the START condition has been transmitted, the TWINT flag in TWCR is set, and TWSR is updated with a status code indicating that the START condition has successfully been sent. 3. The application software should now examine the value of TWSR, to make sure that the START condition was successfully transmitted.
AT90CAN32/64/128 • 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.
18.8 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.
AT90CAN32/64/128 Figure 18-11. Data Transfer in Master Transmitter Mode Device 1 Device 2 MASTER TRANSMITTER SLAVE RECEIVER Device 3 ........ Device n VCC R1 R2 SDA SCL A START condition is sent by writing the following value to TWCR: TWCR value TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE 1 X 1 0 X 1 0 X TWEN must be set to enable the Two-wire Serial Interface, TWSTA must be written to one to transmit a START condition and TWINT must be written to one to clear the TWINT flag.
After a repeated START condition (state 0x10) the Two-wire Serial Interface can access the same slave again, or a new slave without transmitting a STOP condition. Repeated START enables the master to switch between slaves, Master Transmitter mode and Master Receiver mode without losing control of the bus. Table 18-3.
AT90CAN32/64/128 Figure 18-12.
18.8.2 Master Receiver Mode In the Master Receiver Mode, a number of data bytes are received from a slave transmitter (see Figure 18-13). In order to enter a Master mode, a START condition must be transmitted. The format of the following address packet determines whether Master Transmitter or Master Receiver mode is to be entered. If SLA+W is transmitted, MT mode is entered, if SLA+R is transmitted, MR mode is entered.
AT90CAN32/64/128 A REPEATED START condition is generated by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE 1 X 1 0 X 1 0 X value After a repeated START condition (state 0x10) the Two-wire Serial Interface can access the same slave again, or a new slave without transmitting a STOP condition. Repeated START enables the master to switch between slaves, Master Transmitter mode and Master Receiver mode without losing control over the bus. Figure 18-14.
Table 18-4.
AT90CAN32/64/128 To initiate the Slave Receiver mode, TWAR and TWCR must be initialized as follows: TWAR TWA6 TWA5 value TWA4 TWA3 TWA2 TWA1 TWA0 TWGCE Device’s Own Slave Address The upper seven bits are the address to which the Two-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.
Table 18-5.
AT90CAN32/64/128 Figure 18-16. Formats and States in the Slave Receiver Mode Reception of the own slave address and one or more data bytes.
18.8.4 Slave Transmitter Mode In the Slave Transmitter mode, a number of data bytes are transmitted to a master receiver (see Figure 18-17). All the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. Figure 18-17. Data Transfer in Slave Transmitter Mode Device 1 Device 2 SLAVE TRANSMITTER MASTER RECEIVER Device 3 ........
AT90CAN32/64/128 While TWEA is zero, the TWI does not respond to its own slave address. However, the Two-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 Two-wire Serial Bus. In all sleep modes other than Idle mode, the clock system to the TWI is turned off.
Figure 18-18. Formats and States in the Slave Transmitter Mode Reception of the own slave address and one or more data bytes S SLA R A DATA A 0xA8 Arbitration lost as master and addressed as slave DATA 0xB8 A P or S 0xC0 A 0xB0 Last data byte transmitted. Switched to not addressed slave (TWEA = ’0’) A All 1’s P or S 0xC8 From master to slave DATA From slave to master 18.8.
AT90CAN32/64/128 18.8.6 Combining Several TWI Modes In some cases, several TWI modes must be combined in order to complete the desired action. Consider for example reading data from a serial EEPROM. Typically, such a transfer involves the following steps: 1. The transfer must be initiated 2. The EEPROM must be instructed what location should be read 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.
18.9 Multi-master Systems and Arbitration If multiple masters are connected to the same bus, transmissions may be initiated simultaneously by one or more of them. The TWI standard ensures that such situations are handled in such a way that one of the masters will be allowed to proceed with the transfer, and that no data will be lost in the process. An example of an arbitration situation is depicted below, where two masters are trying to transmit data to a slave receiver. Figure 18-20.
AT90CAN32/64/128 This is summarized in Figure 18-21. Possible status values are given in circles. Figure 18-21.
19. Controller Area Network - CAN The Controller Area Network (CAN) protocol is a real-time, serial, broadcast protocol with a very high level of security. The AT90CAN32/64/128 CAN controller is fully compatible with the CAN Specification 2.0 Part A and Part B.
AT90CAN32/64/128 by which the dominant state overwrites the recessive state. The competition for bus allocation is lost by all nodes with recessive transmission and dominant observation. All the "losers" automatically become receivers of the message with the highest priority and do not re-attempt transmission until the bus is available again. 19.2.2 19.2.2.1 Message Formats The CAN protocol supports two message frame formats, the only essential difference being in the length of the identifier.
19.2.2.2 CAN Extended Frame Figure 19-2. CAN Extended Frames Data Frame Bus Idle SOF 11-bit base identifier IDT28..18 SRR IDE 18-bit identifier extension ID17..0 RTR r1 Arbitration Field Interframe Space r0 4-bit DLC DLC4..0 15-bit CRC 0 - 8 bytes Control Field Data Field CRC Field CRC ACK del. ACK del. ACK Field 7 bits End of Frame Intermission Bus Idle 3 bits (Indefinite) Interframe Space Remote Frame Bus Idle Interframe Space SOF 11-bit base identifier IDT28..
AT90CAN32/64/128 Figure 19-3. CAN Bit Construction CAN Frame (producer) Transmission Point (producer) Nominal CAN Bit Time Time Quantum (producer) Segments (producer) SYNC_SEG PROP_SEG PHASE_SEG_1 PHASE_SEG_2 propagation delay Segments (consumer) SYNC_SEG PROP_SEG PHASE_SEG_1 PHASE_SEG_2 Sample Point 19.2.3.2 Synchronization Segment The first segment is used to synchronize the various bus nodes. On transmission, at the start of this segment, the current bit level is output.
The IPT begins at the sample point, is measured in TQ and is fixed at 2TQ for the Atmel CAN. Since Phase Segment 2 also begins at the sample point and is the last segment in the bit time, PS2 minimum shall not be less than the IPT. 19.2.3.8 Bit Lengthening As a result of resynchronization, Phase Segment 1 may be lengthened or Phase Segment 2 may be shortened to compensate for oscillator tolerances.
AT90CAN32/64/128 Figure 19-4. Bus Arbitration Arbitration lost node A TXCAN Node A loses the bus Node B wins the bus node B TXCAN CAN bus SOF ID10 ID9 ID8 ID7 ID6 ID5 ID4 ID3 ID2 ID1 ID0 RTR IDE 19.2.5 --------- Errors The CAN protocol signals any errors immediately as they occur. Three error detection mechanisms are implemented at the message level and two at the bit level: 19.2.5.
19.3 CAN Controller The CAN controller implemented into AT90CAN32/64/128 offers V2.0B Active. This full-CAN controller provides the whole hardware for convenient acceptance filtering and message management. For each message to be transmitted or received this module contains one so called message object in which all information regarding the message (e.g. identifier, data bytes etc.) are stored.
AT90CAN32/64/128 19.4 19.4.1 CAN Channel Configuration The CAN channel can be in: • Enabled mode In this mode: – the CAN channel (internal TxCAN & RxCAN) is enabled, – the input clock is enabled. • Standby mode In standby mode: – the transmitter constantly provides a recessive level (on internal TxCAN) and the receiver is disabled, – input clock is enabled, – the registers and pages remain accessible.
The total number of TQ in a bit time has to be programmed at least from 8 to 25. Figure 19-7. Sample and Transmission Point Bit Timing PRS (3-bit length) PHS1 (3-bit length) CLK Fcan (Tscl) Time Quantum Prescaler BRP IO Sample Point PHS2 (3-bit length) Transmission Point SJW (2-bit length) Figure 19-8. General Structure of a Bit Period 1 /CLK IO CLK IO Bit Rate Prescaler Tscl (TQ) F CAN one nominal bit Data Tsyns(5) Notes: 1. 2. 3. 4. 5.
AT90CAN32/64/128 5. Tsjw = (1 to 4) x Tscl = (SJW[1..0]+ 1) x Tscl Notes: 1. The total number of Tscl (Time Quanta) in a bit time must be from 8 to 25. 2. PHS2[2..0] 2 is programmable to be ≤ PHS1[2..0] and ≥ 1. 19.4.4 Fault Confinement (c.f. Section 19.7 ”Error Management” on page 248). 19.4.5 Overload Frame An overload frame is sent by setting an overload request (OVRQ). After the next reception, the CAN channel sends an overload frame in accordance with the CAN specification.
19.5.2 Operating Modes There is no default mode after RESET. Every MOb has its own fields to control the operating mode. Before enabling the CAN peripheral, each MOb must be configured (ex: disabled mode - CONMOB=00). Table 19-1. MOb Configuration MOb Configuration 0 0 0 1 1 Reply Valid RTR Tag x x Disabled x 0 Tx Data Frame x 1 Tx Remote Frame x 0 Rx Data Frame 0 0 Operating Mode Rx Remote Frame 1 1 1 19.5.2.
AT90CAN32/64/128 2. The MOb is ready to receive a data or a remote frame when the MOb configuration is set (CONMOB). 3. When a frame identifier is received on CAN network, the CAN channel scans all the MObs in receive mode, tries to find the MOb having the highest priority which is matching. 4. On a hit, the IDT, the IDE and the DLC of the matched MOb are updated from the incoming (frame) values. 5.
19.5.3 Acceptance Filter Upon a reception hit (i.e., a good comparison between the ID + RTR + RBn + IDE received and an IDT+ RTRTAG + RBnTAG + IDE specified while taking the comparison mask into account) the IDT + RTRTAG + RBnTAG + IDE received are updated in the MOb (written over the registers). Figure 19-10.
AT90CAN32/64/128 The data index (INDX) is the address pointer to the required data byte. The data byte can be read or write. The data index is automatically incremented after every access if the AINC* bit is reset. A roll-over is implemented, after data index=7 it is data index=0. The first byte of a CAN frame is stored at the data index=0, the second one at the data index=1, ... 19.6 CAN Timer A programmable 16-bit timer is used for message stamping and time trigger communication (TTC). Figure 19-11.
19.7 19.7.1 Error Management Fault Confinement The CAN channel may be in one of the three following states: • Error active (default): The CAN channel takes part in bus communication and can send an active error frame when the CAN macro detects an error. • Error passive: The CAN channel cannot send an active error frame. It takes part in bus communication, but when an error is detected, a passive error frame is sent.
AT90CAN32/64/128 – end-of-frame – error delimiter – overload delimiter • AERR: Acknowledgment error (Tx only). No detection of the dominant bit in the acknowledge slot. Figure 19-13. Error Detection Procedures in a Data Frame Arbitration Bit error Stuff error Form error Tx ACK error SOF Rx Identifier RTR Control Message Data CRC CRC ACK ACK del. del. EOF inter. Bit error Stuff error Form error CRC error 19.7.3 Error Setting The CAN channel can detect some errors on the CAN network.
Figure 19-14. CAN Controller Interrupt Structure CANGIE.4 CANGIE.5 CANGIE.3 ENTX CANSTMOB.6 TXOK[i] CANSTMOB.5 RXOK[i] CANSTMOB.4 BERR[i] CANSTMOB.3 SERR[i] CANSTMOB.2 CERR[i] CANSTMOB.1 FERR[i] CANSTMOB.0 AERR[i] ENRX ENERR CANSIT 1/2 SIT[i] CANIE 1/2 IEMOB[i] 0 CANGIT.7 i CANGIT.4 BXOK CANGIT.3 SERG CANGIT.2 CERG CANGIT.1 FERG CANGIT.0 AERG CANGIT.6 BOFFI CANGIT.5 OVRTIM CANIT CANGIE.2 CANGIE.1 CANGIE.6 CANGIE.7 ENERG ENIT ENBX ENBOFF CAN IT CANGIE.0 19.8.
AT90CAN32/64/128 19.9 CAN Register Description Figure 19-15.
19.10 General CAN Registers 19.10.1 CAN General Control Register - CANGCON Bit 7 6 5 4 3 2 1 0 ABRQ OVRQ TTC SYNTTC LISTEN TEST ENA/STB SWRES 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 CANGCON • Bit 7 – ABRQ: Abort Request This is not an auto resettable bit. – 0 - no request. – 1 - abort request: a reset of CANEN1 and CANEN2 registers is done.
AT90CAN32/64/128 – 0 - standby mode: The on-going transmission (if exists) is normally terminated and the CAN channel is frozen (the CONMOB bits of every MOb do not change). The transmitter constantly provides a recessive level. In this mode, the receiver is not enabled but all the registers and mailbox remain accessible from CPU. Note: A standby mode applied during a reception may corrupt the on-going reception or set the controller in a wrong state.
This flag does not generate an interrupt. – 0 - CAN controller disable: because an enable/standby command is not immediately effective, this status gives the true state of the chosen mode. – 1 - CAN controller enable. • Bit 1 – BOFF: Bus Off Mode BOFF gives the information of the state of the CAN channel. Only entering in bus off mode generates the BOFFIT interrupt. – 0 - no bus off mode. – 1 - bus off mode. • Bit 0 – ERRP: Error Passive Mode ERRP gives the information of the state of the CAN channel.
AT90CAN32/64/128 – 1 - burst receive interrupt: set when the frame buffer receive is completed. • Bit 3 – SERG: Stuff Error General Writing a logical one resets this interrupt flag. – 0 - no interrupt. – 1 - stuff error interrupt: detection of more than 5 consecutive bits with the same polarity. • Bit 2 – CERG: CRC Error General Writing a logical one resets this interrupt flag. – 0 - no interrupt. – 1 - CRC error interrupt: the CRC check on destuffed message does not fit with the CRC field.
– 1- transmit interrupt enabled. • Bit 3 – ENERR: Enable MOb Errors Interrupt – 0 - interrupt disabled. – 1- MOb errors interrupt enabled. • Bit 2 – ENBX: Enable Frame Buffer Interrupt – 0 - interrupt disabled. – 1- frame buffer interrupt enabled. • Bit 1 – ENERG: Enable General Errors Interrupt – 0 - interrupt disabled. – 1- general errors interrupt enabled. • Bit 0 – ENOVRT: Enable CAN Timer Overrun Interrupt – 0 - interrupt disabled. – 1- CAN timer interrupt overrun enabled. 19.10.
AT90CAN32/64/128 19.10.
The period of the CAN controller system clock Tscl is programmable and determines the individual bit timing. BRP[5:0] + 1 Tscl = clkIO frequency If BRP[5..0]=0, see Section 19.4.3 ”Baud Rate” on page 242 and Section • ”Bit 0 – SMP: Sample Point(s)” on page 259. • Bit 0 – Reserved Bit This bit is reserved for future use. For compatibility with future devices, it must be written to zero when CANBT1 is written. 19.10.
AT90CAN32/64/128 • Bit 7– Reserved Bit This bit is reserved for future use. For compatibility with future devices, it must be written to zero when CANBT3 is written. • Bit 6:4 – PHS22:0: Phase Segment 2 This phase is used to compensate for phase edge errors. This segment may be shortened by the re-synchronization jump width. PHS2[2..0] shall be ≥1 and ≤PHS1[2..0] (c.f. Section 19.2.3 ”CAN Bit Timing” on page 236 and Section 19.4.3 ”Baud Rate” on page 242).
19.10.13 CAN TTC Timer Registers - CANTTCL and CANTTCH Bit 7 6 5 4 3 2 TIMTTC7 TIMTTC6 TIMTTC5 TIMTTC4 TIMTTC3 TIMTTC2 1 0 TIMTTC1 TIMTTC0 CANTTCL TIMTTC15 TIMTTC14 TIMTTC13 TIMTTC12 TIMTTC11 TIMTTC10 TIMTTC9 TIMTTC8 CANTTCH Bit 15 14 13 12 11 10 9 8 Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 • Bits 15:0 - TIMTTC15:0: TTC Timer Count CAN TTC timer counter range 0 to 65,535. 19.10.
AT90CAN32/64/128 • Bit 7:4 – MOBNB3:0: MOb Number Selection of the MOb number, the available numbers are from 0 to 14. • Bit 3 – AINC: Auto Increment of the FIFO CAN Data Buffer Index (Active Low) – 0 - auto increment of the index (default value). – 1- no auto increment of the index. • Bit 2:0 – INDX2:0: FIFO CAN Data Buffer Index Byte location of the CAN data byte into the FIFO for the defined MOb. 19.11 MOb Registers The MOb registers has no initial (default) value after RESET. 19.11.
The rising of this flag does not disable the MOb (the corresponding ENMOB-bit of CANEN registers is not cleared). The next matching frame will update the BERR flag. • Bit 3 – SERR: Stuff Error This flag can generate an interrupt. It must be cleared using a read-modify-write software routine on the whole CANSTMOB register. Detection of more than five consecutive bits with the same polarity. This flag can generate an interrupt.
AT90CAN32/64/128 – 00 - disable. – 01 - enable transmission. – 10 - enable reception. – 11 - enable frame buffer reception These bits are not cleared once the communication is performed. The user must re-write the configuration to enable a new communication. • This operation is necessary to be able to reset the BXOK flag. • This operation also set the corresponding bit in the CANEN registers. • Bit 5 – RPLV: Reply Valid Used in the automatic reply mode after receiving a remote frame. – 0 - reply not ready.
Bit 31/23 30/22 29/21 28/20 27/19 26/18 25/17 24/16 Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value - - - - - - - - V2.0 part A • Bit 31:21 – IDT10:0: Identifier Tag Identifier field of the remote or data frame to send. This field is updated with the corresponding value of the remote or data frame received. • Bit 20:3 – Reserved Bits These bits are reserved for future use. For compatibility with future devices, they must be written to zero when CANIDTn are written.
AT90CAN32/64/128 • Bit 0 – RB0TAG: Reserved Bit 0 Tag RB0 bit of the remote or data frame to send. This tag is updated with the corresponding value of the remote or data frame received. 19.11.4 CAN Identifier Mask Registers CANIDM1, CANIDM2, CANIDM3, and CANIDM4 V2.
• Bit 31:3 – IDMSK28:0: Identifier Mask – 0 - comparison true forced - See “Acceptance Filter” on page 246. – 1 - bit comparison enabled - See “Acceptance Filter” on page 246. • Bit 2 – RTRMSK: Remote Transmission Request Mask – 0 - comparison true forced – 1 - bit comparison enabled. • Bit 1 – Reserved Bit Writing zero in this bit is recommended. • Bit 0 – IDEMSK: Identifier Extension Mask – 0 - comparison true forced – 1 - bit comparison enabled. 19.11.
AT90CAN32/64/128 Table 19-2. fclkio (MHz) Examples of CAN Baud Rate Settings for Commonly Frequencies CAN Baudrate (Kbps) 1000 Description Sampling Point 69 % (1) 75 % 500 75 % 250 75 % 200 75 % 125 75 % 100 75 % 1000 67 % (1) 500 75 % 250 75 % 200 75 % 125 75 % 100 75 % 16.000 12.000 Segments Registers TQ (µs) Tbit (TQ) Tprs (TQ) Tph1 (TQ) Tph2 (TQ) Tsjw (TQ) CANBT1 CANBT2 CANBT3 0.0625 16 7 4 4 1 0x00 0x0C 0x36 (2) 0.
Table 19-2. fclkio (MHz) Examples of CAN Baud Rate Settings for Commonly Frequencies (Continued) CAN Baudrate (Kbps) 1000 500 250 Description Sampling Point 63 % (1) TQ (µs) Segments Tbit (TQ) Note: data- - - 1 0x00 0x04 0x12 (2) 69 % (1) 0.125 16 7 4 4 1 0x00 0x0C 0x36 (2) 75 % 0.250 8 3 2 2 1 0x02 0x04 0x13 0.250 16 7 4 4 1 0x02 0x0C 0x37 75 % 75 % 100 75 % 0.500 8 3 2 2 1 0x06 0x04 0x13 0.250 20 8 6 5 1 0x02 0x0E 0x4B 0.
AT90CAN32/64/128 20. Analog Comparator The Analog Comparator compares the input values on the positive pin AIN0 and negative pin AIN1. 20.1 Overview When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator output, ACO, is set. The comparator’s output can be set to trigger the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate interrupt, exclusive to the Analog Comparator.
20.2.2 Analog Comparator Control and Status Register – ACSR Bit 7 6 5 4 3 2 1 0 ACD ACBG ACO ACI ACIE ACIC ACIS1 ACIS0 Read/Write R/W R/W R R/W R/W R/W R/W R/W Initial Value 0 0 N/A 0 0 0 0 0 ACSR • Bit 7 – ACD: Analog Comparator Disable When this bit is written logic one, the power to the Analog Comparator is switched off. This bit can be set at any time to turn off the Analog Comparator. This will reduce power consumption in Active and Idle mode.
AT90CAN32/64/128 • Bits 1, 0 – ACIS1, ACIS0: Analog Comparator Interrupt Mode Select These bits determine which comparator events that trigger the Analog Comparator interrupt. The different settings are shown in Table 20-1. Table 20-1. ACIS1/ACIS0 Settings ACIS1 ACIS0 Interrupt Mode 0 0 Comparator Interrupt on Output Toggle. 0 1 Reserved 1 0 Comparator Interrupt on Falling Output Edge. 1 1 Comparator Interrupt on Rising Output Edge.
20.3.1 Digital Input Disable Register 1 – DIDR1 Bit 7 6 5 4 3 2 1 0 – – – – – – AIN1D AIN0D Read/Write R R R R R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 DIDR1 • Bit 1, 0 – AIN1D, AIN0D: AIN1, AIN0 Digital Input Disable When this bit is written logic one, the digital input buffer on the AIN1/0 pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set.
AT90CAN32/64/128 21. Analog to Digital Converter - ADC 21.1 Features • • • • • • • • • • • • • • 10-bit Resolution 0.5 LSB Integral Non-linearity ± 2 LSB Absolute Accuracy 65 - 260 µs Conversion Time Up to 15 kSPS at Maximum Resolution Eight Multiplexed Single Ended Input Channels Seven Differential input channels Optional Left Adjustment for ADC Result Readout 0 - VCC ADC Input Voltage Range Selectable 2.
Figure 21-1. Analog to Digital Converter Block Schematic ADC CONVERSION COMPLETE IRQ INTERRUPT FLAGS ADTS[2:0] TRIGGER SELECT ADC[9:0] ADPS1 0 ADC DATA REGISTER (ADCH/ADCL) ADPS0 ADPS2 ADIF ADATE ADEN ADSC MUX1 15 ADC CTRL.
AT90CAN32/64/128 the AREF pin minus 1 LSB. Optionally, AVCC or an internal 2.56V reference voltage may be connected to the AREF pin by writing to the REFSn bits in the ADMUX Register. The internal voltage reference may thus be decoupled by an external capacitor at the AREF pin to improve noise immunity. The analog input channel and differential gain are selected by writing to the MUX bits in ADMUX.
Figure 21-2. ADC Auto Trigger Logic ADTS[2:0] PRESCALER START CLKADC ADATE ADIF SOURCE 1 . . . . CONVERSION LOGIC EDGE DETECTOR SOURCE n ADSC Using the ADC Interrupt Flag as a trigger source makes the ADC start a new conversion as soon as the ongoing conversion has finished. The ADC then operates in Free Running mode, constantly sampling and updating the ADC Data Register. The first conversion must be started by writing a logical one to the ADSC bit in ADCSRA.
AT90CAN32/64/128 When initiating a single ended conversion by setting the ADSC bit in ADCSRA, the conversion starts at the following rising edge of the ADC clock cycle. See “Differential Channels” on page 278 for details on differential conversion timing. A normal conversion takes 13 ADC clock cycles. The first conversion after the ADC is switched on (ADEN in ADCSRA is set) takes 25 ADC clock cycles in order to initialize the analog circuitry. The actual sample-and-hold takes place 1.
Figure 21-6. ADC Timing Diagram, Auto Triggered Conversion One Conversion 1 Cycle Number 2 3 4 5 6 7 8 9 Next Conversion 10 11 12 13 1 2 ADC Clock Trigger Source ADATE ADIF ADCH Sign and MSB of Result ADCL LSB of Result Sample & Hold Prescaler Reset Prescaler Reset Conversion Complete MUX and REFS Update Figure 21-7.
AT90CAN32/64/128 initiated immediately after the previous conversion completes, and since CKADC2 is high at this time, all automatically started (i.e., all but the first) Free Running conversions will take 14 ADC clock cycles. If differential channels are used and conversions are started by Auto Triggering, the ADC must be switched off between conversions. When Auto Triggering is used, the ADC prescaler is reset before the conversion is started.
21.5.1 ADC Input Channels When changing channel selections, the user should observe the following guidelines to ensure that the correct channel is selected: • In Single Conversion mode, always select the channel before starting the conversion. The channel selection may be changed one ADC clock cycle after writing one to ADSC. However, the simplest method is to wait for the conversion to complete before changing the channel selection.
AT90CAN32/64/128 another interrupt wakes up the CPU before the ADC conversion is complete, that interrupt will be executed, and an ADC Conversion Complete interrupt request will be generated when the ADC conversion completes. The CPU will remain in active mode until a new sleep command is executed. Note that the ADC will not be automatically turned off when entering other sleep modes than Idle mode and ADC Noise Reduction mode.
1. Keep analog signal paths as short as possible. Make sure analog tracks run over the analog ground plane, and keep them well away from high-speed switching digital tracks. 2. The AVCC pin on the device should be connected to the digital VCC supply voltage via an LC network as shown in Figure 21-9. 3. Use the ADC noise canceler function to reduce induced noise from the CPU. 4. If any ADC port pins are used as digital outputs, it is essential that these do not switch while a conversion is in progress.
AT90CAN32/64/128 Figure 21-10. Offset Error Output Code Ideal ADC Actual ADC Offset Error VREF Input Voltage • Gain Error: After adjusting for offset, the Gain Error is found as the deviation of the last transition (0x3FE to 0x3FF) compared to the ideal transition (at 1.5 LSB below maximum). Ideal value: 0 LSB Figure 21-11.
Figure 21-12. Integral Non-linearity (INL) Output Code INL Ideal ADC Actual ADC VREF Input Voltage • Differential Non-linearity (DNL): The maximum deviation of the actual code width (the interval between two adjacent transitions) from the ideal code width (1 LSB). Ideal value: 0 LSB. Figure 21-13.
AT90CAN32/64/128 For single ended conversion, the result is: V IN ⋅ 1023 ADC = -------------------------V REF where VIN is the voltage on the selected input pin and VREF the selected voltage reference (see Table 21-3 on page 287 and Table 21-4 on page 288). 0x000 represents analog ground, and 0x3FF represents the selected reference voltage minus one LSB.
Table 21-2. Correlation Between Input Voltage and Output Codes VADCn Read code Corresponding decimal value VADCm + VREF /GAIN 0x1FF 511 VADCm + 0.999 VREF /GAIN 0x1FF 511 VADCm + 0.998 VREF /GAIN 0x1FE 510 ... ... ... VADCm + 0.001 VREF /GAIN 0x001 1 VADCm 0x000 0 VADCm - 0.001 VREF /GAIN 0x3FF -1 ... ... ... VADCm - 0.999 VREF /GAIN 0x201 -511 VADCm - VREF /GAIN 0x200 -512 Example 1: – ADMUX = 0xED (ADC3 - ADC2, 10x gain, 2.
AT90CAN32/64/128 21.8 21.8.1 ADC Register Description ADC Multiplexer Selection Register – ADMUX Bit 7 6 5 4 3 2 1 0 REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 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 ADMUX • Bit 7:6 – REFS1:0: Reference Selection Bits These bits select the voltage reference for the ADC, as shown in Table 21-3.
Table 21-4. Input Channel and Gain Selections MUX4..
AT90CAN32/64/128 21.8.2 ADC Control and Status Register A – ADCSRA Bit 7 6 5 4 3 2 1 0 ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 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 ADCSRA • Bit 7 – ADEN: ADC Enable Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off. Turning the ADC off while a conversion is in progress, will terminate this conversion.
• Bits 2:0 – ADPS2:0: ADC Prescaler Select Bits These bits determine the division factor between the XTAL frequency and the input clock to the ADC. Table 21-5. 21.8.
AT90CAN32/64/128 • ADC9:0: ADC Conversion Result These bits represent the result from the conversion, as detailed in “ADC Conversion Result” on page 284. 21.8.4 ADC Control and Status Register B – ADCSRB Bit 7 6 5 4 3 2 1 0 – ACME – – – ADTS2 ADTS1 ADTS0 Read/Write R R/W R R R R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 ADCSRB • Bit 7– Reserved Bit This bit is reserved for future use. For compatibility with future devices, it must be written to zero when ADCSRB is written.
21.8.5 Digital Input Disable Register 0 – DIDR0 Bit 7 6 5 4 3 2 1 0 ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D 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 DIDR0 • Bit 7:0 – ADC7D..ADC0D: ADC7:0 Digital Input Disable When this bit is written logic one, the digital input buffer on the corresponding ADC pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set.
AT90CAN32/64/128 22. JTAG Interface and On-chip Debug System 22.1 Features • JTAG (IEEE std. 1149.1 Compliant) Interface • Boundary-scan Capabilities According to the IEEE std. 1149.
• TCK: Test Clock. JTAG operation is synchronous to TCK. • TDI: Test Data In. Serial input data to be shifted in to the Instruction Register or Data Register (Scan Chains). • TDO: Test Data Out. Serial output data from Instruction Register or Data Register (Scan Chains). 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.
AT90CAN32/64/128 Figure 22-1.
Figure 22-2. TAP Controller State Diagram 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 0 1 0 1 Capture-DR Capture-IR 0 0 0 Shift-DR 1 1 Exit1-DR 0 0 Pause-DR 0 Pause-IR 1 1 0 Exit2-DR Exit2-IR 1 1 Update-DR 22.4 1 Exit1-IR 0 1 0 Shift-IR 1 0 1 Update-IR 0 1 0 TAP Controller The TAP controller is a 16-state finite state machine that controls the operation of the Boundaryscan circuitry, JTAG programming circuitry, or On-chip Debug system.
AT90CAN32/64/128 • 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.
• 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 AVR Studio, may however use one or more of these resources for its internal purpose, leaving less flexibility to the end-user. A list of the On-chip Debug specific JTAG instructions is given in “On-chip Debug Specific JTAG Instructions” on page 298.
AT90CAN32/64/128 22.8 22.8.1 On-chip Debug Related Register in I/O Memory On-chip Debug Register – OCDR Bit 7 6 5 4 3 2 1 0 IDRD/OCDR7 OCDR6 OCDR5 OCDR4 OCDR3 OCDR2 OCDR1 OCDR0 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 OCDR The OCDR Register provides a communication channel from the running program in the microcontroller to the debugger. The CPU can transfer a byte to the debugger by writing to this location.
23. Boundary-scan IEEE 1149.1 (JTAG) 23.1 Features • • • • • 23.2 JTAG (IEEE std. 1149.
AT90CAN32/64/128 23.3.1 Bypass Register The Bypass Register consists of a single Shift Register stage. When the Bypass Register is selected as path between TDI and TDO, the register is reset to 0 when leaving the Capture-DR controller state. The Bypass Register may be used to shorten the scan chain on a system when the other devices are to be tested. 23.3.2 Device Identification Register Figure 23-1 shows the structure of the Device Identification Register. Figure 23-1.
23.3.2.4 Device ID The full Device ID is listed in Table 23-4 following the AT90CAN32/64/128 version. Table 23-4. Device ID Version 23.3.3 JTAG Device ID (Hex) AT90CAN32 revision A 0x0958103F AT90CAN64 revision A 0x0968103F AT90CAN128 revision A 0x0978103F Reset Register The Reset Register is a test data register used to reset the part. Since the AVR tri-states Port Pins when reset, the Reset Register can also replace the function of the unimplemented optional JTAG instruction HIGHZ.
AT90CAN32/64/128 23.4.1 EXTEST (0x0) Mandatory JTAG instruction for selecting the Boundary-scan Chain as data register for testing circuitry external to the AVR package. For port-pins, Pull-up Disable, Output Control, Output Data, and Input Data are all accessible in the scan chain. For Analog circuits having off-chip connections, the interface between the analog and the digital logic is in the scan chain.
• Shift-DR: The Bypass Register cell between TDI and TDO is shifted. 23.5 23.5.1 Boundary-scan Related Register in I/O Memory MCU Control Register – MCUCR The MCU Control Register contains control bits for general MCU functions. Bit 7 6 5 4 3 2 1 0 JTD – – PUD – – IVSEL IVCE Read/Write R/W R R R/W R R R/W R/W Initial Value 0 0 0 0 0 0 0 0 MCUCR • Bits 7 – JTD: JTAG Interface Disable When this bit is zero, the JTAG interface is enabled if the JTAGEN Fuse is programmed.
AT90CAN32/64/128 When no alternate port function is present, the Input Data – ID – corresponds to the PINxn Register value (but ID has no synchronizer), Output Data corresponds to the PORT Register, Output Control corresponds to the Data Direction – DD Register, and the Pull-up Enable – PUExn – corresponds to logic expression PUD · DDxn · PORTxn. Digital alternate port functions are connected outside the dotted box in Figure 23-4 to make the scan chain read the actual pin value.
Figure 23-4. General Port Pin Schematic Diagram See Boundary-scan Description for Details! PUExn PUD Q D DDxn Q CLR RESET OCxn WDx Q Pxn ODxn D PORTxn Q CLR WPx IDxn DATA BUS RDx RESET RRx SLEEP SYNCHRONIZER D Q L Q D RPx Q PINxn Q CLK I/O PUD: PUExn: OCxn: ODxn: IDxn: SLEEP: 23.6.
AT90CAN32/64/128 Figure 23-5. Additional Scan Signal for the Two-wire Interface PUExn OCxn ODxn TWIEN Pxn SRC Slew-rate limited IDxn 23.6.3 Scanning the RESET Pin The RESET pin accepts 3V or 5V active low logic for standard reset operation, and 12V active high logic for High Voltage Parallel programming. An observe-only cell as shown in Figure 23-6 is inserted both for the 3V or 5V reset signal - RSTT, and the 12V reset signal - RSTHV. Figure 23-6.
Figure 23-7. Boundary-scan Cells for Oscillators and Clock Options XTAL1 / TOSC1 To Next Cell ShiftDR XTAL2 / TOSC2 To Next Cell Oscillator EXTEST ShiftDR From Digital Logic 0 ENABLE OUTPUT To System Logic 1 FF1 0 D Q D Q 1 From Previous Cell ClockDR 0 D G Q 1 UpdateDR From Previous Cell ClockDR Table 23-5 summaries the scan registers for the external clock pin XTAL1, oscillators with XTAL1/XTAL2 connections as well as external Timer2 clock pin TOSC1 and 32kHz Timer2 Oscillator.
AT90CAN32/64/128 Figure 23-8. Analog Comparator BANDGAP REFERENCE ACBG ACO AC_IDLE ACME ADCEN ADC MULTIPLEXER OUTPUT Figure 23-9. General Boundary-scan cell Used for Signals for Comparator and ADC To Next Cell ShiftDR EXTEST From Digital Logic/ From Analog Ciruitry To Analog Circuitry/ To Digital Logic 0 1 0 D Q D Q 1 G From Previous Cell Table 23-6.
23.6.6 Scanning the ADC Figure 23-10 shows a block diagram of the ADC with all relevant control and observe signals. The Boundary-scan cell from Figure 23-9 is attached to each of these signals. The ADC need not be used for pure connectivity testing, since all analog inputs are shared with a digital port pin as well. Figure 23-10. Analog to Digital Converter VCCREN AREF IREFEN 2.56V ref To Comparator PASSEN MUXEN_7 ADC_7 MUXEN_6 ADC_6 MUXEN_5 ADC_5 MUXEN_4 ADC_4 ADCBGEN SCTEST 1.
AT90CAN32/64/128 Table 23-7.
Table 23-7. 312 Boundary-scan Signals for the ADC(1) (Continued) Signal Name Direction as Seen from the ADC Description GNDEN Input Ground the negative input to comparator when true 0 0 HOLD Input Sample & Hold signal. Sample analog signal when low. Hold signal when high. If gain stages are used, this signal must go active when ACLK is high.
AT90CAN32/64/128 Table 23-7. Boundary-scan Signals for the ADC(1) (Continued) Direction as Seen from the ADC Description Input Switch-cap TEST enable. Output from x10 gain stage send out to Port Pin having ADC_4 0 0 ST Input Output of gain stages will settle faster if this signal is high first two ACLK periods after AMPEN goes high. 0 0 VCCREN Input Selects Vcc as the ACC reference voltage.
The recommended values from Table 23-7 are used unless other values are given in the algorithm in Table 23-8. Only the DAC and port pin values of the Scan Chain are shown. The column “Actions” describes what JTAG instruction to be used before filling the Boundary-scan Register with the succeeding columns. The verification should be done on the data scanned out when scanning in the data on the same row in the table. Table 23-8. Algorithm for Using the ADC MUXEN HOLD PRECH PA3. Data PA3. Control PA3.
AT90CAN32/64/128 corresponds to FF1, and PXn. Pullup_enable corresponds to FF2. Bit 2, 3, 4, and 5 of Port C is not in the scan chain, since these pins constitute the TAP pins when the JTAG is enabled. Table 23-9.
Table 23-9. 316 AT90CAN32/64/128 Boundary-scan Order (Continued) Bit Number Signal Name 164 NEGSEL_1 163 NEGSEL_0 162 PASSEN 161 PRECH 160 SCTEST 159 ST 158 VCCREN 157 PE0.Data 156 PE0.Control 155 PE0.Pullup_Enable 154 PE1.Data 153 PE1.Control 152 PE1.Pullup_Enable 151 PE2.Data 150 PE2.Control 149 PE2.Pullup_Enable 148 PE3.Data 147 PE3.Control 146 PE3.Pullup_Enable 145 PE4.Data 144 PE4.Control 143 PE4.Pullup_Enable 142 PE5.Data 141 PE5.Control 140 PE5.
AT90CAN32/64/128 Table 23-9. AT90CAN32/64/128 Boundary-scan Order (Continued) Bit Number Signal Name 126 PB2.Control 125 PB2.Pullup_Enable 124 PB3.Data 123 PB3.Control 122 PB3.Pullup_Enable 121 PB4.Data 120 PB4.Control 119 PB4.Pullup_Enable 118 PB5.Data 117 PB5.Control 116 PB5.Pullup_Enable 115 PB6.Data 114 PB6.Control 113 PB6.Pullup_Enable 112 PB7.Data 111 PB7.Control 110 PB7.Pullup_Enable 109 PG3.Data 108 PG3.Control 107 PG3.Pullup_Enable 106 PG4.
Table 23-9. 318 AT90CAN32/64/128 Boundary-scan Order (Continued) Bit Number Signal Name 88 PD1.Control 87 PD1.Pullup_Enable 86 PD2.Data 85 PD2.Control 84 PD2.Pullup_Enable 83 PD3.Data 82 PD3.Control 81 PD3.Pullup_Enable 80 PD4.Data 79 PD4.Control 78 PD4.Pullup_Enable 77 PD5.Data 76 PD5.Control 75 PD5.Pullup_Enable 74 PD6.Data 73 PD6.Control 72 PD6.Pullup_Enable 71 PD7.Data 70 PD7.Control 69 PD7.Pullup_Enable 68 PG0.Data 67 PG0.Control 66 PG0.
AT90CAN32/64/128 Table 23-9. AT90CAN32/64/128 Boundary-scan Order (Continued) Bit Number Signal Name 50 PC4.Data 49 PC4.Control 48 PC4.Pullup_Enable 47 PC5.Data 46 PC5.Control 45 PC5.Pullup_Enable 44 PC6.Data 43 PC6.Control 42 PC6.Pullup_Enable 41 PC7.Data 40 PC7.Control 39 PC7.Pullup_Enable 38 PG2.Data 37 PG2.Control 36 PG2.Pullup_Enable 35 PA7.Data 34 PA7.Control 33 PA7.Pullup_Enable 32 PA6.Data 31 PA6.Control 30 PA6.Pullup_Enable 29 PA5.Data 28 PA5.
Table 23-9. Bit Number Signal Name 12 PA0.Pullup_Enable Port A 11 PF3.Data Port F 10 PF3.Control 9 PF3.Pullup_Enable 8 PF2.Data 7 PF2.Control 6 PF2.Pullup_Enable 5 PF1.Data 4 PF1.Control 3 PF1.Pullup_Enable 2 PF0.Data 1 PF0.Control 0 PF0.Pullup_Enable Notes: 23.8 AT90CAN32/64/128 Boundary-scan Order (Continued) Comment Module 1. PRIVATE_SIGNAL should always be scanned-in as zero.
AT90CAN32/64/128 24. Boot Loader Support – Read-While-Write Self-Programming The Boot Loader Support provides a real Read-While-Write Self-Programming mechanism for downloading and uploading program code by the MCU itself. This feature allows flexible application software updates controlled by the MCU using a Flash-resident Boot Loader program.
sections that are configurable by the BOOTSZ Fuses as described above, the Flash is also divided into two fixed sections, the Read-While-Write (RWW) section and the No Read-WhileWrite (NRWW) section. The limit between the RWW- and NRWW sections is given in Table 247 on page 334 and Figure 24-2 on page 324. The main difference between the two sections is: • When erasing or writing a page located inside the RWW section, the NRWW section can be read during the operation.
AT90CAN32/64/128 Figure 24-1. Read-While-Write vs.
Figure 24-2.
AT90CAN32/64/128 • Allow software update in the entire Flash. See Table 24-2 and Table 24-3 for further details. The Boot Lock bits can be set in software and in Serial or Parallel Programming mode, but they can be cleared by a Chip Erase command only. The general Write Lock (Lock Bit mode 2) does not control the programming of the Flash memory by SPM instruction.
grammed, the Reset Vector will always point to the Boot Loader Reset and the fuse can only be changed through the serial or parallel programming interface. Table 24-4. Boot Reset Fuse(1) BOOTRST Note: 24.5.1 Reset Address 1 Reset Vector = Application Reset (address 0x0000) 0 Reset Vector = Boot Loader Reset (see Table 24-6 on page 334) 1.
AT90CAN32/64/128 An 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 330 for details. • Bit 2 – PGWRT: Page Write If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles executes Page Write, with the data stored in the temporary buffer.
same page in both the page erase and page write operation. Once a programming operation is initiated, the address is latched and the Z-pointer can be used for other operations. The (E)LPM instruction 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 24-3.
AT90CAN32/64/128 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 alternative 2 is used, it is not possible to read the old data while loading since the page is already erased.
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. 24.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.
AT90CAN32/64/128 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 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.
3. Keep the AVR core in Power-down sleep mode during periods of low VCC. This will prevent the CPU from attempting to decode and execute instructions, effectively protecting the SPMCSR Register and thus the Flash from unintentional writes. 24.7.11 Programming Time for Flash when Using SPM The calibrated RC Oscillator is used to time Flash accesses. Table 24-5 shows the typical programming time for Flash accesses from the CPU. Table 24-5. 24.7.
AT90CAN32/64/128 sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256 ldi spmcsrval, (1<
Boot Loader Parameters In Table 24-6 through Table 24-8, the parameters used in the description of the Self-Programming are given.
AT90CAN32/64/128 AT90CAN128 AT90CAN64 AT90CAN32 Variable Value Explanation of Different Variables Used in Figure 24-3 on page 328 and the Mapping to the Z-Pointer(1) Variable Name Device Table 24-8. PCMSB 13 Most significant bit in the program counter. (The program counter is 14 bits PC[13:0]) PAGEMSB 6 Most significant bit which is used to address the words within one page (128 words in a page requires 7 bits PC [6:0]).
25. Memory Programming 25.1 Program and Data Memory Lock Bits The AT90CAN32/64/128 provides six Lock bits which can be left unprogrammed (“1”) or can be programmed (“0”) to obtain the additional features listed in Table 25-2. The Lock bits can only be erased to “1” with the Chip Erase command. Table 25-1.
AT90CAN32/64/128 Table 25-2. Lock Bit Protection Modes(1)(2) (Continued) Memory Lock Bits Protection Type 2 1 0 SPM is not allowed to write to the Boot Loader section. 3 0 0 SPM is not allowed to write to the Boot Loader section, and 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.
Table 25-4. Fuse High Byte (Continued) Fuse High Byte Bit No Description Default Value (6) BOOTSZ1 2 Select Boot Size (see Table 24-6 for details) 0 (programmed)(2) BOOTSZ0 1 Select Boot Size(6) (see Table 24-6 for details) 0 (programmed)(2) BOOTRST 0 Select Reset Vector(7) (see Table 24-6 for details) 1 (unprogrammed) Notes: 1. The SPIEN Fuse is not accessible in serial programming mode. 2. The default value of BOOTSZ1..0 results in maximum Boot Size.
AT90CAN32/64/128 25.3 Signature Bytes All Atmel microcontrollers have a three-byte signature code which identifies the device. This code can be read in both serial and parallel mode, also when the device is locked. The three bytes reside in a separate address space. Table 25-6.
Figure 25-1. Parallel Programming +2.7 - +5.5V RDY/BSY PD1 OE PD2 WR PD3 BS1 PD4 XA0 PD5 XA1 PD6 PAGEL PD7 +12 V VCC +2.7 - +5.5V AVCC PB7 - PB0 DATA RESET BS2 PA0 XTAL1 GND 25.5.2 Pin Mapping Table 25-7. 25.5.3 Signal Name in Programming Mode Pin Name I/O RDY/BSY PD1 O 0: Device is busy programming, 1: Device is ready for new command. OE PD2 I Output Enable (Active low). WR PD3 I Write Pulse (Active low).
AT90CAN32/64/128 Table 25-9. XA1 and XA0 Coding XA1 XA0 Action when XTAL1 is Pulsed 0 0 Load Flash or EEPROM Address (High or low address byte determined by BS1). 0 1 Load Data (High or Low data byte for Flash determined by BS1). 1 0 Load Command 1 1 No Action, Idle Table 25-10. Command Byte Bit Coding Command Byte 25.5.
25.6 25.6.1 Parallel Programming Enter Programming Mode The following algorithm puts the device in parallel programming mode: 1. Apply power between VCC and GND. 2. Set RESET to “0” and toggle XTAL1 at least six times. 3. Set the Prog_enable pins listed in Table 25-8 on page 340 to “0000” and wait at least 100 ns. 4. Apply 11.5 - 12.5V to RESET. Any activity on Prog_enable pins within 100 ns after +12V has been applied to RESET, will cause the device to fail entering programming mode. 5.
AT90CAN32/64/128 1. Set XA1, XA0 to “10”. This enables command loading. 2. Set BS1 to “0”. 3. Set DATA to “0001 0000”. This is the command for Write Flash. 4. Give XTAL1 a positive pulse. This loads the command. B: Load Address Low byte 1. Set XA1, XA0 to “00”. This enables address loading. 2. Set BS1 to “0”. This selects low address. 3. Set DATA = Address low byte (0x00 - 0xFF). 4. Give XTAL1 a positive pulse. This loads the address low byte. C: Load Data Low Byte 1. Set XA1, XA0 to “01”.
1. 1. Set XA1, XA0 to “10”. This enables command loading. 2. Set DATA to “0000 0000”. This is the command for No Operation. 3. Give XTAL1 a positive pulse. This loads the command, and the internal write signals are reset. Figure 25-2. Addressing the Flash Which is Organized in Pages(1) PCMSB PROGRAM COUNTER PAGEMSB PCPAGE PCWORD PAGE ADDRESS WITHIN THE FLASH WORD ADDRESS WITHIN A PAGE PROGRAM MEMORY PAGE PAGE INSTRUCTION WORD PCWORD[PAGEMSB:0]: 00 01 02 PAGEEND Note: 1.
AT90CAN32/64/128 25.6.5 Programming the EEPROM The EEPROM is organized in pages, see Table 25-12 on page 341. When programming the EEPROM, the program data is latched into a page buffer. This allows one page of data to be programmed simultaneously. The programming algorithm for the EEPROM data memory is as follows (refer to “Programming the Flash” on page 342 for details on Command, Address and Data loading): 1. A: Load Command “0001 0001”. 2. G: Load Address High Byte (0x00 - 0xFF). 3.
25.6.7 Reading the EEPROM The algorithm for reading the EEPROM memory is as follows (refer to “Programming the Flash” on page 342 for details on Command and Address loading): 1. A: Load Command “0000 0011”. 2. G: Load Address High Byte (0x00 - 0xFF). 3. B: Load Address Low Byte (0x00 - 0xFF). 4. Set OE to “0”, and BS1 to “0”. The EEPROM Data byte can now be read at DATA. 5. Set OE to “1”. 25.6.
AT90CAN32/64/128 Figure 25-5. Programming the FUSES Waveforms Write Fuse Low byte DATA A C 0x40 DATA XX Write Fuse high byte A C 0x40 DATA XX Write Extended Fuse byte A C 0x40 DATA XX XA1 XA0 BS1 BS2 XTAL1 WR RDY/BSY RESET +12V OE PAGEL 25.6.11 Programming the Lock Bits The algorithm for programming the Lock bits is as follows (refer to “Programming the Flash” on page 342 for details on Command and Data loading): 1. A: Load Command “0010 0000”. 2. C: Load Data Low Byte.
Figure 25-6. Mapping Between BS1, BS2 and the Fuse and Lock Bits During Read Fuse Low Byte 0 Extended Fuse Byte 1 0 DATA BS2 Lock Bits 0 Fuse High Byte 1 1 BS1 BS2 25.6.13 Reading the Signature Bytes The algorithm for reading the Signature bytes is as follows (refer to “Programming the Flash” on page 342 for details on Command and Address loading): 1. A: Load Command “0000 1000”. 2. B: Load Address Low Byte (0x00 - 0x02). 3. Set OE to “0”, and BS1 to “0”.
AT90CAN32/64/128 Figure 25-7. Serial Programming and Verify(1) +2.7 - +5.5V VCC PDI PE0 PDO PE1 SCK PB1 +2.7 - +5.5V AVCC XTAL1 RESET GND Notes: 1. If the device is clocked by the internal Oscillator, it is no need to connect a clock source to the XTAL1 pin. When programming the EEPROM, an auto-erase cycle is built into the self-timed programming operation (in the Serial mode ONLY) and there is no need to first execute the Chip Erase instruction.
1. Power-up sequence: Apply power between VCC and GND while RESET and SCK are set to “0”. In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, 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.
AT90CAN32/64/128 are meant to contain 0xFF, can be skipped. This does not apply if the EEPROM is re-programmed without chip erasing the device. In this case, data polling cannot be used for the value 0xFF, and the user will have to wait at least tWD_EEPROM before programming the next byte. See Table 25-14 for tWD_EEPROM value. Table 25-14. Minimum Wait Delay Before Writing the Next Flash or EEPROM Location Symbol Minimum Wait Delay tWD_FUSE 4.5 ms tWD_FLASH 4.5 ms tWD_EEPROM 9.0 ms tWD_ERASE 9.
Table 25-15. Serial Programming Instruction Set (Continued) Set a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don’t care Instruction Format(1) Instruction Byte 1 Byte 2(2) Byte 3 Operation(1) Byte4 Load EEPROM Memory Page (page access) 1100 0001 0000 0000 0000 0bbb iiii iiii Write EEPROM Memory Page (page access) 1100 0010 000x aaaa bbbb b000 xxxx xxxx Write EEPROM page at address a:b.
AT90CAN32/64/128 the JTAG pins for Boundary-scan or On-chip Debug. In these cases the JTAG pins must be dedicated for this purpose. During programming the clock frequency of the TCK Input must be less than the maximum frequency of the chip. The System Clock Prescaler can not be used to divide the TCK Clock Input into a sufficiently low frequency. As a definition in this datasheet, the LSB is shifted in and out first of all Shift Registers. 25.9.
25.9.1.1 AVR_RESET (0xC) The AVR specific public JTAG instruction for setting the AVR device in the Reset mode or taking the device out from the Reset mode. The TAP controller is not reset by this instruction. The one bit Reset Register is selected as data register. Note that the reset will be active as long as there is a logic “one” in the Reset Chain. The output from this chain is not latched. The active states are: • Shift-DR: The Reset Register is shifted by the TCK input. 25.9.1.
AT90CAN32/64/128 • Capture-DR: The content of the selected Flash byte is captured into the Flash Data Byte Register. The AVR automatically alternates between reading the low and the high byte for each new Capture-DR state, starting with the low byte for the first Capture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte.
25.9.2.3 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 25-16. The state sequence when shifting in the programming commands is illustrated in Figure 25-12. Figure 25-11.
AT90CAN32/64/128 Table 25-16. JTAG Programming Instruction (Continued) Set a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don’t care Instruction TDI Sequence(1)(2) TDO Sequence(1)(2) Notes 2g. Write Flash Page 0110111_00000000 0110101_00000000 0110111_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx xxxxxxx_xxxxxxxx (3) 2h. Poll for Page Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (4) 3a.
Table 25-16. JTAG Programming Instruction (Continued) Set a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don’t care Instruction TDI Sequence(1)(2) TDO Sequence(1)(2) Notes 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 (4) 6h.
AT90CAN32/64/128 Table 25-16. JTAG Programming Instruction (Continued) Set a = address high bits, b = address low bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don’t care Instruction TDI Sequence(1)(2) TDO Sequence(1)(2) 10b. Load Address Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 10c. Read Calibration Byte 0110110_00000000 0110111_00000000 xxxxxxx_xxxxxxxx xxxxxxx_oooooooo 11a.
Figure 25-12. State Machine Sequence for Changing/Reading the Data Word 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 0 0 1 1 Capture-DR Capture-IR 0 0 Shift-DR 0 Shift-IR 1 Exit1-DR 0 0 Pause-DR 0 Pause-IR 1 1 0 Exit2-DR Exit2-IR 1 1 Update-DR 25.9.2.
AT90CAN32/64/128 ture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte. This ensures that the first data is captured from the first address set up by PROG_COMMANDS, and reading the last location in the page makes the program counter increment into the next page. Figure 25-13.
25.9.3.3 Performing Chip Erase 1. Enter JTAG instruction PROG_COMMANDS. 2. Start Chip Erase using programming instruction 1a. 3. Poll for Chip Erase complete using programming instruction 1b, or wait for tWLRH_CE (refer to Table 26-15 on page 382). 25.9.3.4 Programming the Flash 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash write using programming instruction 2a. 3. Load address High byte using programming instruction 2b. 4. Load address Low byte using programming instruction 2c. 5.
AT90CAN32/64/128 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.
25.9.3.9 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 corresponding lock bit, a “1” will leave the lock bit unchanged. 4. Write Lock bits using programming instruction 7c. 5. Poll for Lock bit write complete using programming instruction 7d, or wait for tWLRH (refer to Table 26-15 on page 382). 25.9.3.10 Reading the Fuses and Lock Bits 1.
AT90CAN32/64/128 26. Electrical Characteristics (1) 26.1 Absolute Maximum Ratings* Industrial Operating Temperature ...................– 40°C to +85°C Storage Temperature ....................................– 65°C to +150°C Voltage on any Pin except RESET with respect to Ground .............................. – 0.5V to VCC+0.5V Voltage on RESET with respect to Ground.... – 0.5V to +13.0V Voltage on VCC with respect to Ground............. – 0.5V to 6.
26.2 DC Characteristics TA = -40°C to +85°C, VCC = 2.7V to 5.5V (unless otherwise noted) Symbol Parameter Condition Min. VIL Input Low Voltage Except XTAL1 and RESET pins VIL1 Input Low Voltage VIL2 Max. Units – 0.5 0.2 Vcc (1) V XTAL1 pin - External Clock Selected – 0.5 0.1 Vcc (1) V Input Low Voltage RESET pin – 0.5 0.2 Vcc (1) V VIH Input High Voltage Except XTAL1 and RESET pins 0.6 Vcc (2) Vcc + 0.5 V VIH1 Input High Voltage XTAL1 pin - External Clock Selected 0.
AT90CAN32/64/128 TA = -40°C to +85°C, VCC = 2.7V to 5.5V (unless otherwise noted) (Continued) Symbol Parameter Condition Min. IACLK Analog Comparator Input Leakage Current VCC = 5V Vin = VCC/2 – 50 Analog Comparator Propagation Delay Common Mode Vcc/2 VCC = 2.7V 170 ns tACID VCC = 5.0V 180 ns Notes: Typ. Max. Units 50 nA 1. “Max” means the highest value where the pin is guaranteed to be read as low 2. “Min” means the lowest value where the pin is guaranteed to be read as high 3.
Table 26-1. Symbol 26.4 External Clock Drive (Continued) Parameter VCC = 2.7 - 5.5V VCC = 4.5 - 5.5V Min. Min. Max. 50 Units Max. tCLCX Low Time 25 ns tCLCH Rise Time 1.6 0.5 μs tCHCL Fall Time 1.6 0.5 μs ΔtCLCL Change in period from one clock cycle to the next 2 2 % Maximum Speed vs. VCC Maximum frequency is depending on VCC. As shown in Figure 26-2., the Maximum Frequency vs. VCC curve is linear between 1.8V < VCC < 4.5V.
AT90CAN32/64/128 26.5 Two-wire Serial Interface Characteristics Table 26-3 describes the requirements for devices connected to the Two-wire Serial Bus. The AT90CAN32/64/128 Two-wire Serial Interface meets or exceeds these requirements under the noted conditions. Timing symbols refer to Figure 26-3. Table 26-3. Two-wire Serial Bus Requirements Symbol Parameter VIL VIH tr Max Units Input Low-voltage – 0.5 0.3 Vcc V Input High-voltage 0.7 Vcc Vcc + 0.5 V – V 0 0.4 V 20 + 0.
2. Required only for fSCL > 100 kHz. 3. Cb = capacitance of one bus line in pF. 4. fCK = CPU clock frequency 5. This requirement applies to all AT90CAN32/64/128 Two-wire Serial Interface operation. Other devices connected to the Two-wire Serial Bus need only obey the general fSCL requirement. 6. The actual low period generated by the AT90CAN32/64/128 Two-wire Serial Interface is (1/fSCL - 2/fCK), thus fCK must be greater than 6 MHz for the low time requirement to be strictly met at fSCL = 100 kHz. 7.
AT90CAN32/64/128 Table 26-4. SPI Timing Parameters (Continued) Description Mode Min. 13 Setup Slave 10 14 Hold Slave tck 15 SCK to out Slave 16 SCK to SS high Slave 17 SS high to tri-state Slave 18 SS low to SCK Slave Note: Typ. Max. 15 ns 20 10 2 • tck In SPI Programming mode the minimum SCK high/low period is: - 2 tCLCL for fCK < 12 MHz - 3 tCLCL for fCK >12 MHz Figure 26-4.
26.7 CAN Physical Layer Characteristics Only pads dedicated to the CAN communication belong to the physical layer. Table : CAN Physical Layer Characteristics (1) Parameter 1 2 Notes: TxCAN output delay RxCAN input delay Condition Min. Max. Units Vcc=2.7 V Load=20 pF VOL/VOH=VCC/2 9 Vcc=4.5 V Load=20 pF VOL/VOH=VCC/2 5.3 ns Vcc=2.7 V VIL/VIH=VCC/2 9+ Vcc=4.5 V VIL/VIH=VCC/2 7.2 + 1 / fCLKIO(2) 1 / fCLKIO(2) 1. Characteristics for CAN physical layer have not yet been finalized. 2.
AT90CAN32/64/128 26.8 ADC Characteristics Table 26-5. Symbol ADC Characteristics, Single Ended Channels Min(1) Typ(1) Max(1) Parameter Condition Resolution Single Ended Conversion 10 Bits Single Ended Conversion VREF = 4V, Vcc = 4V ADC clock = 200 kHz 1.
Table 26-6. Symbol ADC Characteristics, Differential Channels Parameter Condition Min(1) Typ(1) Max(1) Units Differential Conversion Gain = 1x or 10x 8 Bits Differential Conversion Gain = 200x 7 Bits Absolute accuracy Gain = 1x, 10x or 200x VREF = 4V, Vcc = 5V ADC clock = 50 - 200 kHz 1 LSB Integral Non-linearity (INL) (Accuracy after Calibration for Offset and Gain Error) Gain = 1x, 10x or 200x VREF = 4V, Vcc = 5V ADC clock = 50 - 200 kHz 0.
AT90CAN32/64/128 26.9 External Data Memory Characteristics Table 26-7. External Data Memory Characteristics, VCC = 4.5 - 5.5 Volts, No Wait-state 8 MHz Oscillator Symbol Variable Oscillator Parameter Unit Min. 0 1/tCLCL Oscillator Frequency 1 tLHLL ALE Pulse Width Max. 115 Min. Max. 0.0 16 MHz 1.0 tCLCL – 10 ns (1) 2 tAVLL Address Valid A to ALE Low 57.
Table 26-9. External Data Memory Characteristics, VCC = 4.5 - 5.5 Volts, SRWn1 = 1, SRWn0 = 0 8 MHz Oscillator Symbol Variable Oscillator Parameter Unit Min. Max. Min. Max. 0.0 16 0 1/tCLCL Oscillator Frequency 10 tRLDV Read Low to Data Valid 12 tRLRH RD Pulse Width 365 3.0 tCLCL – 10 ns 15 tDVWH Data Valid to WR High 375 3.0 tCLCL ns 16 tWLWH WR Pulse Width 365 3.0 tCLCL – 10 ns 325 MHz 3.0 tCLCL – 50 ns Table 26-10. External Data Memory Characteristics, VCC = 4.
AT90CAN32/64/128 Table 26-11. External Data Memory Characteristics, VCC = 2.7 - 5.5 Volts, No Wait-state (Continued) 4 MHz Oscillator Symbol Variable Oscillator Parameter Unit Min. 11 tRHDX Data Hold After RD High 12 tRLRH 13 Max. Min. Max. 0 0 ns RD Pulse Width 235 1.0 tCLCL – 15 ns tDVWL Data Setup to WR Low 105 0.5 tCLCL – 20 (1) ns 14 tWHDX Data Hold After WR High 235 1.0 tCLCL – 15 ns 15 tDVWH Data Valid to WR High 250 1.0 tCLCL ns 16 tWLWH WR Pulse Width 235 1.
Table 26-14. External Data Memory Characteristics, VCC = 2.7 - 5.5 Volts, SRWn1 = 1, SRWn0 = 1 (Continued) 4 MHz Oscillator Symbol Variable Oscillator Parameter Unit Min. Max. Min. Max. 14 tWHDX Data Hold After WR High 485 2.0 tCLCL – 15 ns 15 tDVWH Data Valid to WR High 750 3.0 tCLCL ns 16 tWLWH WR Pulse Width 735 3.0 tCLCL – 15 ns Figure 26-6. External Memory Timing (SRWn1 = 0, SRWn0 = 0) T1 T2 T3 T4 System Clock (CLKCPU ) 1 ALE 4 A15:8 7 Prev. addr.
AT90CAN32/64/128 Figure 26-7. External Memory Timing (SRWn1 = 0, SRWn0 = 1) T1 T2 T3 T4 T5 System Clock (CLKCPU ) 1 ALE 4 A15:8 7 Prev. addr. Address 15 DA7:0 Prev. data 13 3a Address Data XX 14 16 6 Write 2 WR 9 3b DA7:0 (XMBK = 0) Data 5 Read Address 11 10 8 12 RD Figure 26-8. External Memory Timing (SRWn1 = 1, SRWn0 = 0) T1 T2 T3 T4 T5 T6 System Clock (CLKCPU ) 1 ALE 4 A15:8 7 Address Prev. addr. 15 DA7:0 Prev.
Figure 26-9. External Memory Timing (SRWn1 = 1, SRWn0 = 1)(1) T1 T2 T3 T6 T5 T4 T7 System Clock (CLKCPU ) 1 ALE 4 A15:8 7 Address Prev. addr. 15 DA7:0 Prev. data 13 3a Address XX Data 14 16 6 Write 2 WR 9 3b Address 11 Data 5 Read DA7:0 (XMBK = 0) 10 8 12 RD Note: 1. The ALE pulse in the last period (T4-T7) is only present if the next instruction accesses the RAM (internal or external). 26.10 Parallel Programming Characteristics Figure 26-10.
AT90CAN32/64/128 Figure 26-11. Parallel Programming Timing, Loading Sequence with Timing Requirements(1) LOAD ADDRESS (LOW BYTE) LOAD DATA LOAD DATA (HIGH BYTE) LOAD DATA (LOW BYTE) tXLPH t XLXH LOAD ADDRESS (LOW BYTE) tPLXH XTAL1 BS1 PAGEL DATA ADDR0 (Low Byte) DATA (Low Byte) DATA (High Byte) ADDR1 (Low Byte) XA0 XA1 Note: 1. The timing requirements shown in Figure 26-10 (i.e., tDVXH, tXHXL, and tXLDX) also apply to loading operation. Figure 26-12.
Note: 1. The timing requirements shown in Figure 26-10 (i.e., tDVXH, tXHXL, and tXLDX) also apply to reading operation. Table 26-15. Parallel Programming Characteristics, VCC = 5V ± 10% Symbol Parameter Min. VPP Programming Enable Voltage 11.
AT90CAN32/64/128 27. Decoupling Capacitors The operating frequency (i.e. system clock) of the processor determines in 95% of cases the value needed for microcontroller decoupling capacitors. The hypotheses used as first evaluation for decoupling capacitors are: • The operating frequency (fop) supplies itself the maximum peak levels of noise. The main peaks are located at fop and 2 • fop. • An SMC capacitor connected to 2 micro-vias on a PCB has the following characteristics: – 1.
28. AT90CAN32/64/128 Typical Characteristics • The following charts show typical behavior. These figures are not tested during manufacturing. All current consumption measurements are performed with all I/O pins configured as inputs and with internal pull-ups enabled. A sine wave generator with rail-to-rail output is used as clock source. • The power consumption in Power-down mode is independent of clock selection.
AT90CAN32/64/128 Figure 28-2. Active Supply Current vs. Frequency (1 - 16 MHz) ACTIVE SUPPLY CURRENT vs. FREQUENCY (25°C, 1 - 16 MHz) 40 35 30 5.50V 5.00V 4.50V 4.00V 3.30V 3.00V 2.70V Icc (mA) 25 20 15 10 5 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Frequency (MHz) Figure 28-3. Active Supply Current vs. Vcc (Internal RC Oscillator 8 MHz) ACTIVE SUPPLY CURRENT vs. Vcc (Internal RC Oscillator 8 MHz) 20 18 16 Icc (mA) 14 12 85°C 25°C -40°C 10 8 6 4 2 0 2.5 3 3.5 4 4.5 5 5.
Figure 28-4. Active Supply Current vs. Vcc (Internal RC Oscillator 1 MHz) ACTIVE SUPPLY CURRENT vs. Vcc (Internal RC Oscillator 1 MHz) 3 2.5 Icc (mA) 2 85°C 1.5 25°C -40°C 1 0.5 0 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 28-5. Active Supply Current vs. Vcc (32 kHz Watch Crystal) ACTIVE SUPPLY CURRENT vs. Vcc (32 kHz Watch Crystal) 140 120 Icc (uA) 100 80 25°C 60 40 20 0 2.5 3 3.5 4 4.5 5 5.
AT90CAN32/64/128 28.2 Idle Supply Current Figure 28-6. Idle Supply Current vs. Frequency (0.1 - 1.0 MHz) IDLE SUPPLY CURRENT vs. FREQUENCY (25°C, 0.1 - 1 MHz) 1.6 1.4 1.2 5.50V 5.00V 4.50V 4.00V 3.30V 3.00V 2.70V Icc (mA) 1 0.8 0.6 0.4 0.2 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Frequency (MHz) Figure 28-7. Idle Supply Current vs. Frequency (1 - 16 MHz) IDLE SUPPLY CURRENT vs. FREQUENCY (25°C, 1 - 16 MHz) 25 Icc (mA) 20 5.50V 5.00V 4.50V 4.00V 3.30V 3.00V 2.
Figure 28-8. Idle Supply Current vs. Vcc (Internal RC Oscillator 8 MHz) IDLE SUPPLY CURRENT vs. Vcc (Internal RC Oscillator 8 MHz) 14 12 Icc (mA) 10 85°C 25°C -40°C 8 6 4 2 0 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 28-9. Idle Supply Current vs. Vcc (Internal RC Oscillator 1 MHz) IDLE SUPPLY CURRENT vs. Vcc (Internal RC Oscillator 1 MHz) 1.8 1.6 1.4 Icc (mA) 1.2 85°C 1 25°C 0.8 -40°C 0.6 0.4 0.2 0 2.5 3 3.5 4 4.5 5 5.
AT90CAN32/64/128 Figure 28-10. Idle Supply Current vs. Vcc (32 kHz Watch Crystal) IDLE SUPPLY CURRENT vs. Vcc (32 KHz Watch Crystal) 60 50 Icc (uA) 40 30 25°C 20 10 0 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) 28.3 Power-down Supply Current Figure 28-11. Power-down Supply Current vs. Vcc (Watchdog Timer Disabled) POWER-DOWN SUPPLY CURRENT vs. Vcc (Watchdog Timer Disabled) 9 8 7 Icc (uA) 6 85°C 25°C -40°C 5 4 3 2 1 0 2.5 3 3.5 4 4.5 5 5.
Figure 28-12. Power-down Supply Current vs. Vcc (Watchdog Timer Enabled) POWER-DOWN SUPPLY CURRENT vs. Vcc (Watchdog Timer Enabled) 25 22.5 20 Icc (uA) 17.5 15 85°C 25°C -40°C 12.5 10 7.5 5 2.5 0 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) 28.4 Power-save Supply Current Figure 28-13. Power-save Supply Current vs. Vcc (Watchdog Timer Disabled) POWER-SAVE SUPPLY CURRENT vs. Vcc (Watchdog Timer Disabled) 25 22.5 20 Icc (uA) 17.5 15 12.5 25°C 10 7.5 5 2.5 0 2.5 3 3.5 4 4.5 5 5.
AT90CAN32/64/128 28.5 Standby Supply Current Figure 28-14. Power-save Supply Current vs. Vcc (25°C, Watchdog Timer Disabled) STANDBY SUPPLY CURRENT vs. Vcc (25°C, Watchdog Timer Disabled) 0.2 0.18 0.16 Icc (mA) 0.14 6 MHZ Xtal 4 MHZ Res 2 MHZ Xtal 2 MHZ Res 0.12 0.1 0.08 0.06 0.04 0.02 0 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) 28.6 Pin Pull-up Figure 28-15. I/O Pin Pull-up Resistor Current vs. Input Voltage (Vcc = 5V) I/O PIN PULL-UP RESISTOR CURRENT vs.
Figure 28-16. I/O Pin Pull-up Resistor Current vs. Input Voltage (Vcc = 2.7V) I/O PIN PULL-UP RESISTOR CURRENT vs. INPUT VOLTAGE (Vcc = 2.7V) 0 -10 -20 I IO (uA) -30 85°C 25°C -40°C -40 -50 -60 -70 -80 -90 0 0.5 1 1.5 2 2.5 3 V IO (V) Figure 28-17. Reset Pull-up Resistor Current vs. Reset Pin Voltage (Vcc = 5V) RESET PULL-UP RESISTOR CURRENT vs.
AT90CAN32/64/128 Figure 28-18. Reset Pull-up Resistor Current vs. Reset Pin Voltage (Vcc = 2.7V) RESET PULL-UP RESISTOR CURRENT vs. RESET PIN VOLTAGE (Vcc = 2.7V) 0 -10 I RESET (uA) -20 85°C 25°C -40°C -30 -40 -50 -60 -70 0 0.5 1 1.5 2 2.5 3 V RESET (V) 28.7 Pin Driver Strength Figure 28-19. I/O Pin Source Current vs. Output Voltage (Vcc = 5V) I/O PIN SOURCE CURRENT vs. OUTPUT VOLTAGE (Vcc = 5V) 0 -10 -20 I OH (mA) -30 85°C 25°C -40°C -40 -50 -60 -70 -80 -90 2.5 3 3.5 4 4.
Figure 28-20. I/O Pin Source Current vs. Output Voltage (Vcc = 2.7V) I/O PIN SOURCE CURRENT vs. OUTPUT VOLTAGE (Vcc = 2.7V) 0 -5 I OH (mA) -10 85°C 25°C -40°C -15 -20 -25 -30 0.5 1 1.5 2 2.5 3 V OH (V) Figure 28-21. I/O Pin Sink Current vs. Output Voltage (Vcc = 5V) I/O PIN SINK CURRENT vs. OUTPUT VOLTAGE (Vcc = 5V) 90 80 70 I OL (mA) 60 85°C 25°C -40°C 50 40 30 20 10 0 0 0.5 1 1.5 2 2.
AT90CAN32/64/128 Figure 28-22. I/O Pin Sink Current vs. Output Voltage (Vcc = 2.7V) I/O PIN SINK CURRENT vs. OUTPUT VOLTAGE (Vcc = 2.7V) 35 30 I OL (mA) 25 85°C 25°C -40°C 20 15 10 5 0 0 0.5 1 1.5 2 2.5 V OL (V) 28.8 Pin Thresholds and Hysteresis Figure 28-23. I/O Input Threshold Voltage vs. Vcc (VIH, I/O Pin Read as “1”) I/O PIN INPUT THRESHOLD VOLTAGE vs. VCC (VIH, I/O PIN READ AS "1") 2 Threshold (V) 1.75 1.5 85°C 1.25 25°C -40°C 1 0.75 0.5 2.5 3 3.5 4 4.5 5 5.
Figure 1. I/O Input Threshold Voltage vs. Vcc (VIL, I/O Pin Read as “0”) I/O PIN INPUT THRESHOLD VOLTAGE vs. VCC (VIL, I/O PIN READ AS "0") 2 Threshold (V) 1.75 1.5 85°C 1.25 25°C -40°C 1 0.75 0.5 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 2. I/O Input Hysteresis vs. Vcc I/O PIN INPUT HYSTERESIS vs. VCC 0.6 Threshold (V) 0.5 0.4 85°C 0.3 25°C -40°C 0.2 0.1 0 2.5 3 3.5 4 4.5 5 5.
AT90CAN32/64/128 28.9 BOD Thresholds and Analog Comparator Offset Figure 28-24. BOD Thresholds vs. Temperature (BOD level is 4.1V) BOD THRESHOLDS vs. TEMPERATURE (BOD level is 4.1V) 4.4 Threshold (V) 4.2 4 Rising Vcc Falling Vcc 3.8 3.6 3.4 -60 -40 -20 0 20 40 60 80 100 Temp (°C) Figure 28-25. BOD Thresholds vs. Temperature (BOD level is 2.7V) BOD THRESHOLDS vs. TEMPERATURE (BOD level is 2.7V) 3 Threshold (V) 2.8 2.6 Rising Vcc Falling Vcc 2.4 2.
Figure 28-26. Bandgap Voltage vs. Operating Voltage BANDGAP VOLTAGE vs. OPERATING VOLTAGE 1.14 Bandgap Voltage (V) 1.13 1.12 85°C 1.11 25°C -40°C 1.1 1.09 1.08 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 28-27. Analog Comparator Offset vs. Common Mode Voltage (Vcc = 5V) ANALOG COMPARATOR OFFSET vs. COMMON MODE VOLTAGE (Vcc = 5V) Comparator Offset Voltage (V) 0.012 0.01 0.008 85°C 0.006 25°C 0.004 -40°C 0.002 0 -0.002 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.
AT90CAN32/64/128 28.10 Internal Oscillator Speed Figure 28-28. Watchdog Oscillator Frequency vs. Operating Voltage WATCHDOG OSCILLATOR FREQUENCY vs. VCC 1200 1150 F WATCHDOG (kHz) 1100 1050 85°C 1000 25°C -40°C 950 900 850 800 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 28-29. Calibrated 8 MHz RC Oscillator Frequency vs. Temperature CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs. TEMPERATURE 8.8 8.6 F RC (MHz) 8.4 8.2 2.7V 8 4.0V 5.5V 7.8 7.6 7.4 7.
Figure 28-30. Calibrated 8 MHz RC Oscillator Frequency vs. Operating Voltage CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs. VCC 10 9.5 F RC (MHz) 9 8.5 85°C 8 25°C -40°C 7.5 7 6.5 6 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 28-31. Calibrated 8 MHz RC Oscillator Frequency vs. OSCCAL Value CALIBRATED 8MHz RC OSCILLATOR FREQUENCY vs.
AT90CAN32/64/128 28.11 Current Consumption of Peripheral Units Figure 28-32. Brownout Detector Current vs. Operating Voltage BROWNOUT DETECTOR CURRENT vs. Vcc 35 30 Icc (uA) 25 85°C 25°C -40°C 20 15 10 5 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 28-33. ADC Current vs. Operating Voltage (ADC at 1 MHz) ADC CURRENT vs. Vcc (ADC at 1 MHz) 300 250 Icc (uA) 200 85°C 25°C -40°C 150 100 50 0 2.5 3 3.5 4 4.5 5 5.
Figure 28-34. AREF External Reference Current vs. Operating Voltage AREF EXTERNAL REFERENCE CURRENT vs. Vcc 200 180 IAREF (uA) 160 140 85°C 25°C -40°C 120 100 80 60 40 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) Figure 28-35. Analog Comparator Current vs. Operating Voltage ANALOG COMPARATOR CURRENT vs. Vcc 120 100 I CC (uA) 80 85°C 25°C -40°C 60 40 20 0 2.5 3 3.5 4 4.5 5 5.
AT90CAN32/64/128 Figure 28-36. Programming Current vs. Operating Voltage PROGRAMMING CURRENT vs. Vcc 25 I CC (mA) 20 15 85°C 25°C -40°C 10 5 0 2.5 3 3.5 4 4.5 5 5.5 Vcc (V) 28.12 Current Consumption in Reset and Reset Pulse Width Figure 28-37. Reset Supply Current vs. Operating Voltage (0.1 - 1.0 MHz) (Excluding Current Through the Reset Pull-up) RESET SUPPLY CURRENT vs. FREQUENCY (25°C, 0.1 - 1 MHz) (EXCLUDING CURRENT THROUGH THE RESET PULL-UP) 0.25 Icc (mA) 0.2 5.50V 5.00V 4.50V 4.
Figure 28-38. Reset Supply Current vs. Operating Voltage (1 - 16 MHz) (Excluding Current Through the Reset Pull-up) RESET SUPPLY CURRENT vs. FREQUENCY (1 - 16 MHz) (EXCLUDING CURRENT THROUGH THE RESET PULL-UP) 3.5 3 5.50V 2.5 Icc (mA) 5.00V 4.50V 2 4.00V 1.5 3.30V 3.00V 1 2.70V 0.5 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Frequency (MHz) Figure 28-39. Minimum Reset Pulse Width vs. Operating Voltage MINIMUM RESET PULSE WIDTH vs.
AT90CAN32/64/128 29.
Address Name (0xBE) Reserved (0xBD) Reserved (0xBC) TWCR TWINT (0xBB) TWDR TWDR7 (0xBA) TWAR TWAR6 (0xB9) TWSR (0xB8) TWBR (0xB7) Reserved 406 Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page TWEA TWSTA TWSTO TWWC TWEN TWDR6 TWDR5 TWDR4 TWDR3 TWDR2 – TWIE page 212 TWDR1 TWDR0 TWAR5 TWAR4 TWAR3 TWAR2 TWAR1 TWAR0 TWGCE page 214 page 214 TWS7 TWS6 TWS5 TWS4 TWS3 – TWPS1 TWPS0 page 213 TWBR7 TWBR6 TWBR5 TWBR4 TWBR3 TWBR2 TWBR1 TWBR0 page
AT90CAN32/64/128 Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page (0x7C) ADMUX REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 page 287 (0x7B) ADCSRB – ACME – – – ADTS2 ADTS1 ADTS0 page 291, 269 (0x7A) ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 page 289 (0x79) ADCH - / ADC9 - / ADC8 - / ADC7 - / ADC6 - / ADC5 - / ADC4 ADC9 / ADC3 ADC8 / ADC2 page 290 (0x78) ADCL ADC7 / ADC1 ADC6 / ADC0 ADC5 / - ADC4 / - ADC3 / - ADC2 / - ADC1
Address Name 0x1A (0x3A) Reserved 0x19 (0x39) Reserved Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page 0x18 (0x38) TIFR3 – – ICF3 – OCF3C OCF3B OCF3A TOV3 page 143 0x17 (0x37) TIFR2 – – – – – – OCF2A TOV2 page 162 0x16 (0x36) TIFR1 – – ICF1 – OCF1C OCF1B OCF1A TOV1 page 143 0x15 (0x35) TIFR0 – – – – – – OCF0A TOV0 page 112 0x14 (0x34) PORTG – – – PORTG4 PORTG3 PORTG2 PORTG1 PORTG0 page 92 0x13 (0x33) DDRG – – – DDG4 DDG3 DDG2
AT90CAN32/64/128 30.
Mnemonics Operands Description Operation Flags BRIE k Branch if Interrupt Enabled if ( I = 1) then PC ← PC + k + 1 None #Clocks 1/2 BRID k Branch if Interrupt Disabled if ( I = 0) then PC ← PC + k + 1 None 1/2 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
AT90CAN32/64/128 Mnemonics Operands Description Operation Flags #Clocks 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 None 1 MCU CONTROL INSTRUCTIONS NOP No Operation SLEEP Sleep (see specific descr. for Sleep function) None 1 WDR BREAK Watchdog Reset Break (see specific descr.
31. Ordering Information Ordering Code (1) Speed (MHz) Power Supply (V) Package Operation Range Product Marking AT90CAN32-16AI 16 2.7 - 5.5 A2 64 Industrial (-40° to +85°C) AT90CAN32-16AI AT90CAN32-16MI 16 2.7 - 5.5 Z64-1 Industrial (-40° to +85°C) AT90CAN32-16MI AT90CAN32-16AU 16 2.7 - 5.5 A2 64 Industrial (-40° to +85°C) Green AT90CAN32-16AU AT90CAN32-16MU 16 2.7 - 5.5 Z64-1 Industrial (-40° to +85°C) Green AT90CAN32-16MU AT90CAN64-16AI 16 2.7 - 5.
AT90CAN32/64/128 32.1 TQFP64 64 PINS THIN QUAD FLAT PACK D 0O to 7O A L 64 e 1 E E1 f J C 11O / 13O TOP VIEW SIDE VIEW A2 DRAWINGS NOT SCALED 0.100 mm LEAD COPLANARITY MM INCH Min Max Min Max A ---- 1.20 ---- 0.047 A2 0.95 1.05 0.037 0.041 C 0.09 0.20 0.004 0.008 D 16.00 BSC 0.630 BSC D1 14.00 BSC 0.551 BSC E 16.00 BSC 0.630 BSC E1 14.00 BSC 0.551 BSC J 0.05 0.15 0.002 0.006 L 0.45 0.75 0.018 0.030 e f 0.80 BSC 0.30 0.45 0.0315 BSC 0.012 0.
32.
AT90CAN32/64/128 415 7679H–CAN–08/08
33. Errata 33.1 33.1.1 Errata Summary AT90CAN32 RevB (Date code ≥ 0107) • CAN acknowledge error in 3-sample mode with prescaler =1 • CAN transmission after 3-bit intermission • Asynchronous Timer-2 wakes up without interrupt 33.1.
AT90CAN32/64/128 Let’s consider 4 sections in the Flash, described below: Table 33-1.
minimum delay will be 39-bit time in CAN2.0B. See CAN2.0A CAN2.0B frame timings below. T1 T2 CAN 2.0A 19-bit time minimum (RXOK) 15-bit CRC CRC ACK del. ACK del. CRC Field ACK Field 7 bits 3 bits End of Frame Intermission SOF 11-bit identifier ID10..0 RTR IDE Arbitration Field 4-bit DLC DLC4..0 r0 Control Field T1 T2 CAN 2.0B 39-bit time minimum (RXOK) 15-bit CRC CRC ACK del. ACK del.
AT90CAN32/64/128 4. Reset of Timer-2 flags in asynchronous mode In asynchronous mode, a writing in any register of the TIMER-2 (TCCR2A, TCNT2 & OCR2A) automatically clears TOV2 and OCF2A flags in TFIR register. Problem fix / workaround – TOV2: Do not write in Timer-2 registers if TCNT2 is equal to 0xFF, 0x00 or 0x01. – OCF2A: Do not write in Timer-2 registers if TCNT2 and OCR2A differ from -1, 0 or 1. 3.
34. Datasheet Revision History for AT90CAN32/64/128 Please note that the page numbers in this section refer to this document. The revision noted in this section refer to the document revision. 34.1 Changes from 7679G - 03/08 to 7679H - 08/08 1. Minor corrections throughout the document. 34.2 Changes from 7679F - 11/07 to 7679G - 03/08 1. Added errata problem 8 on 416. 34.3 Changes from 7679E - 07/07 to 7679F - 11/07 1. Updated “Errata” on page 416. 2.
AT90CAN32/64/128 Features ..................................................................................................... 1 1 Description ............................................................................................... 2 1.1 Comparison Between AT90CAN32, AT90CAN64 and AT90CAN128 ................2 1.2 Part Description ..................................................................................................2 1.3 Disclaimer ...................................................
6 7 8 9 5.9 Timer/Counter2 Oscillator .................................................................................43 5.10 System Clock Prescaler ....................................................................................44 Power Management and Sleep Modes ................................................. 46 6.1 Idle Mode ..........................................................................................................47 6.2 ADC Noise Reduction Mode ..........................
AT90CAN32/64/128 12.7 Modes of Operation ........................................................................................104 12.8 Timer/Counter Timing Diagrams .....................................................................108 12.9 8-bit Timer/Counter Register Description .......................................................109 13 16-bit Timer/Counter (Timer/Counter1 and Timer/Counter3) ........... 113 13.1 Features .....................................................................
17 USART (USART0 and USART1) .......................................................... 177 17.1 Features ..........................................................................................................177 17.2 Overview .........................................................................................................177 17.3 Dual USART ...................................................................................................177 17.4 Clock Generation .........................
AT90CAN32/64/128 19.12 Examples of CAN Baud Rate Setting .............................................................266 20 Analog Comparator ............................................................................. 269 20.1 Overview .........................................................................................................269 20.2 Analog Comparator Register Description .......................................................269 20.3 Analog Comparator Multiplexed Input ..............
24 Boot Loader Support – Read-While-Write Self-Programming ......... 321 24.1 Features ..........................................................................................................321 24.2 Application and Boot Loader Flash Sections ..................................................321 24.3 Read-While-Write and No Read-While-Write Flash Sections .........................321 24.4 Boot Loader Lock Bits .....................................................................................
AT90CAN32/64/128 28.5 Standby Supply Current ..................................................................................391 28.6 Pin Pull-up ......................................................................................................391 28.7 Pin Driver Strength .........................................................................................393 28.8 Pin Thresholds and Hysteresis .......................................................................395 28.
Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-enYvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel Japan 9F, Tonetsu Shinkawa Bldg.