Atmega32A DataSheet Complete DS40002072A 4
Atmega32A DataSheet Complete DS40002072A 4
Atmega32A DataSheet Complete DS40002072A 4
VPOT
VCC
VRST
RESET
tTOUT
TIME-OUT
INTERNAL
RESET
VCC VBOT+
VBOT-
RESET
TIME-OUT tTOUT
INTERNAL
RESET
CK
WATCHDOG
OSCILLATOR
Bit 7 6 5 4 3 2 1 0
– – – WDTOE WDE WDP2 WDP1 WDP0 WDTCR
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
1. In the same operation, write a logic one to WDTOE and WDE. A logic one must be written to WDE even
though it is set to one before the disable operation starts.
2. Within the next four clock cycles, write a logic 0 to WDE. This disables the Watchdog.
The following code example shows one assembly and one C function for turning off the WDT. The example
assumes that interrupts are controlled (for example by disabling interrupts globally) so that no interrupts will occur
during execution of these functions.
12. Interrupts
This section describes the specifics of the interrupt handling as performed in ATmega32A. For a general explana-
tion of the AVR interrupt handling, refer to “Reset and Interrupt Handling” on page 21.
When the BOOTRST Fuse is unprogrammed, the Boot section size set to 4Kbytes and the IVSEL bit in the GICR
Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and
Interrupt Vector Addresses is:
Address Labels Code Comments
$000 RESET: ldi r16,high(RAMEND); Main program start
$001 out SPH,r16 ; Set Stack Pointer to top of RAM
$002 ldi r16,low(RAMEND)
$003 out SPL,r16
$004 sei ; Enable interrupts
$005 <instr> xxx
;
.org $3802
$3802 jmp EXT_INT0 ; IRQ0 Handler
$3804 jmp EXT_INT1 ; IRQ1 Handler
:. :.. : ;
$3828 jmp SPM_RDY ; Store Program Memory Ready Handler
When the BOOTRST Fuse is programmed and the Boot section size set to 4Kbytes, the most typical and general
program setup for the Reset and Interrupt Vector Addresses is:
Address Labels Code Comments
.org $002
$002 jmp EXT_INT0 ; IRQ0 Handler
$004 jmp EXT_INT1 ; IRQ1 Handler
:. :.. : ;
$028 jmp SPM_RDY ; Store Program Memory Ready Handler
;
.org $3800
$3800 RESET: ldi r16,high(RAMEND); Main program start
$3801 out SPH,r16 ; Set Stack Pointer to top of RAM
$3802 ldi r16,low(RAMEND)
$3803 out SPL,r16
$3804 sei ; Enable interrupts
$3805 <instr> xxx
When the BOOTRST Fuse is programmed, the Boot section size set to 4Kbytes and the IVSEL bit in the GICR
Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and
Interrupt Vector Addresses is:
Address Labels Code Comments
.org $3800
$3800 jmp RESET ; Reset handler
$3802 jmp EXT_INT0 ; IRQ0 Handler
$3804 jmp EXT_INT1 ; IRQ1 Handler
:. :.. : ;
$3828 jmp SPM_RDY ; Store Program Memory Ready Handler
;
$382A RESET: ldi r16,high(RAMEND); Main program start
$382B out SPH,r16 ; Set Stack Pointer to top of RAM
$382C ldi r16,low(RAMEND)
$382D out SPL,r16
Bit 7 6 5 4 3 2 1 0
INT1 INT0 INT2 – – – IVSEL IVCE GICR
Read/Write R/W R/W R/W R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
13.1 Overview
All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that
the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the
SBI and CBI instructions. The same applies when changing drive value (if configured as output) or enabling/dis-
abling of pull-up resistors (if configured as input). Each output buffer has symmetrical drive characteristics with
both high sink and source capability. The pin driver is strong enough to drive LED displays directly. All port pins
have individually selectable pull-up resistors with a supply-voltage invariant resistance. All I/O pins have protection
diodes to both VCC and Ground as indicated in Figure 13-1. Refer to “Electrical Characteristics” on page 286 for a
complete list of parameters.
R pu
Pxn Logic
C pin
See
"General Digital I/O" for
Details
All registers and bit references in this section are written in general form. A lower case “x” represents the number-
ing letter for the port, and a lower case “n” represents the bit number. However, when using the register or bit
defines in a program, the precise form must be used, that is, PORTB3 for bit no. 3 in Port B, here documented gen-
erally as PORTxn. The physical I/O Registers and bit locations are listed in “Register Description” on page 70.
Three I/O memory address locations are allocated for each port, one each for the Data Register – PORTx, Data
Direction Register – DDRx, and the Port Input Pins – PINx. The Port Input Pins I/O location is read only, while the
Data Register and the Data Direction Register are read/write. In addition, the Pull-up Disable – PUD bit in SFIOR
disables the pull-up function for all pins in all ports when set.
Using the I/O port as General Digital I/O is described in “Ports as General Digital I/O” on page 57. Most port pins
are multiplexed with alternate functions for the peripheral features on the device. How each alternate function inter-
feres with the port pin is described in “Alternate Port Functions” on page 61. Refer to the individual module sections
for a full description of the alternate functions.
Note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port
as general digital I/O.
PUD
Q D
DDxn
Q CLR
WDx
RESET
RDx
DATA BUS
Pxn Q D
PORTxn
Q CLR
WPx
RESET
SLEEP RRx
SYNCHRONIZER
RPx
D Q D Q
PINxn
L Q Q
clk I/O
Note: 1. WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O, SLEEP, and PUD are common
to all ports.
Switching between input with pull-up and output low generates the same problem. The user must use either the tri-
state ({DDxn, PORTxn} = 0b00) or the output high state ({DDxn, PORTxn} = 0b11) as an intermediate step.
Table 13-1 summarizes the control signals for the pin value.
SYSTEM CLK
SYNC LATCH
PINxn
tpd, max
tpd, min
Consider the clock period starting shortly after the first falling edge of the system clock. The latch is closed when
the clock is low, and goes transparent when the clock is high, as indicated by the shaded region of the “SYNC
LATCH” signal. The signal value is latched when the system clock goes low. It is clocked into the PINxn Register at
the succeeding positive clock edge. As indicated by the two arrows tpd,max and tpd,min, a single signal transition on
the pin will be delayed between ½ and 1½ system clock period depending upon the time of assertion.
When reading back a software assigned pin value, a nop instruction must be inserted as indicated in Figure 13-4.
The out instruction sets the “SYNC LATCH” signal at the positive edge of the clock. In this case, the delay tpd
through the synchronizer is one system clock period.
SYSTEM CLK
r16 0xFF
SYNC LATCH
PINxn
tpd
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 pre-
viously discussed, a nop instruction is included to be able to read back the value recently assigned to some of the
pins.
Note: 1. For the assembly program, two temporary registers are used to minimize the time from pull-ups are set on pins 0,
1, 6, and 7, until the direction bits are correctly set, defining bit 2 and 3 as low and redefining bits 0 and 1 as strong
high drivers.