- •Features
- •Pin Configurations
- •Overview
- •Block Diagram
- •Pin Descriptions
- •Port A (PA7..PA0)
- •Port B (PB7..PB0)
- •Port C (PC7..PC0)
- •Port D (PD7..PD0)
- •Port E (PE7..PE0)
- •Port F (PF7..PF0)
- •Port G (PG4..PG0)
- •RESET
- •XTAL1
- •XTAL2
- •AVCC
- •AREF
- •AVR CPU Core
- •Introduction
- •Architectural Overview
- •Status Register
- •Stack Pointer
- •Interrupt Response Time
- •SRAM Data Memory
- •Data Memory Access Times
- •EEPROM Data Memory
- •EEPROM Read/Write Access
- •I/O Memory
- •Overview
- •ATmega103 Compatibility
- •Address Latch Requirements
- •Pull-up and Bus-keeper
- •Timing
- •XMEM Register Description
- •Using all 64KB Locations of External Memory
- •Clock Systems and their Distribution
- •CPU Clock – clkCPU
- •I/O Clock – clkI/O
- •Flash Clock – clkFLASH
- •ADC Clock – clkADC
- •Clock Sources
- •Crystal Oscillator
- •External RC Oscillator
- •External Clock
- •Timer/Counter Oscillator
- •Idle Mode
- •Power-down Mode
- •Power-save Mode
- •Standby Mode
- •Extended Standby Mode
- •Analog to Digital Converter
- •Analog Comparator
- •Brown-out Detector
- •Internal Voltage Reference
- •Watchdog Timer
- •Port Pins
- •System Control and Reset
- •Resetting the AVR
- •Reset Sources
- •Power-on Reset
- •External Reset
- •Brown-out Detection
- •Watchdog Reset
- •Watchdog Timer
- •Timed Sequences for Changing the Configuration of the Watch Dog Timer
- •Safety Level 0
- •Safety Level 1
- •Safety Level 2
- •Interrupts
- •I/O-Ports
- •Introduction
- •Configuring the Pin
- •Reading the Pin Value
- •Alternate Port Functions
- •Alternate Functions of Port A
- •Alternate Functions of Port B
- •Alternate Functions of Port C
- •Alternate Functions of Port D
- •Alternate Functions of Port E
- •Alternate Functions of Port F
- •Alternate Functions of Port G
- •Port A Data Register – PORTA
- •Port B Data Register – PORTB
- •Port C Data Register – PORTC
- •Port D Data Register – PORTD
- •Port E Data Register – PORTE
- •Port F Data Register – PORTF
- •Port G Data Register – PORTG
- •External Interrupts
- •8-bit Timer/Counter0 with PWM and Asynchronous Operation
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Output Compare Unit
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •Timer/Counter Prescaler
- •16-bit Timer/Counter (Timer/Counter1 and Timer/Counter3)
- •Overview
- •Registers
- •Definitions
- •Compatibility
- •Counter Unit
- •Input Capture Unit
- •Input Capture Trigger Source
- •Noise Canceler
- •Using the Input Capture Unit
- •Output Compare Units
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •16-bit Timer/Counter Register Description
- •Internal Clock Source
- •Prescaler Reset
- •External Clock Source
- •8-bit Timer/Counter2 with PWM
- •Overview
- •Registers
- •Definitions
- •Counter Unit
- •Output Compare Unit
- •Force Output Compare
- •Modes of Operation
- •Normal Mode
- •Fast PWM Mode
- •Phase Correct PWM Mode
- •Overview
- •Description
- •Timing Example
- •Slave Mode
- •Master Mode
- •SPI Control Register – SPCR
- •SPI Status Register – SPSR
- •SPI Data Register – SPDR
- •Data Modes
- •USART
- •Dual USART
- •Overview
- •AVR USART vs. AVR UART – Compatibility
- •Clock Generation
- •External Clock
- •Synchronous Clock Operation
- •Frame Formats
- •Parity Bit Calculation
- •USART Initialization
- •Sending Frames with 5 to 8 Data Bit
- •Sending Frames with 9 Data Bit
- •Parity Generator
- •Disabling the Transmitter
- •Receiving Frames with 5 to 8 Data Bits
- •Receiving Frames with 9 Data Bits
- •Receiver Error Flags
- •Parity Checker
- •Disabling the Receiver
- •Flushing the Receive Buffer
- •Asynchronous Data Recovery
- •Using MPCM
- •Two-wire Serial Interface
- •Features
- •TWI Terminology
- •Electrical Interconnection
- •Transferring Bits
- •START and STOP Conditions
- •Address Packet Format
- •Data Packet Format
- •Multi-master Bus Systems, Arbitration and Synchronization
- •Overview of the TWI Module
- •Scl and SDA Pins
- •Bit Rate Generator Unit
- •Bus Interface Unit
- •Address Match Unit
- •Control Unit
- •TWI Register Description
- •TWI Bit Rate Register – TWBR
- •TWI Control Register – TWCR
- •TWI Status Register – TWSR
- •TWI Data Register – TWDR
- •Using the TWI
- •Transmission Modes
- •Master Transmitter Mode
- •Master Receiver Mode
- •Slave Receiver Mode
- •Slave Transmitter Mode
- •Miscellaneous States
- •Analog Comparator
- •Analog Comparator Multiplexed Input
- •Analog to Digital Converter
- •Features
- •Operation
- •Starting a Conversion
- •Differential Gain Channels
- •ADC Input Channels
- •ADC Voltage Reference
- •ADC Noise Canceler
- •Analog Input Circuitry
- •ADC Accuracy Definitions
- •ADC Conversion Result
- •ADLAR = 0:
- •ADLAR = 1:
- •Features
- •Overview
- •Test Access Port – TAP
- •TAP Controller
- •PRIVATE0; $8
- •PRIVATE1; $9
- •PRIVATE2; $A
- •PRIVATE3; $B
- •Bibliography
- •Features
- •System Overview
- •Data Registers
- •Bypass Register
- •Device Identification Register
- •Reset Register
- •Boundary-scan Chain
- •EXTEST; $0
- •IDCODE; $1
- •SAMPLE_PRELOAD; $2
- •AVR_RESET; $C
- •BYPASS; $F
- •Boundary-scan Chain
- •Scanning the Digital Port Pins
- •Scanning the RESET Pin
- •Scanning the Clock Pins
- •Scanning the ADC
- •Boot Loader Features
- •Application Section
- •Boot Loader Section – BLS
- •Boot Loader Lock Bits
- •Performing a Page Write
- •Using the SPM Interrupt
- •Setting the Boot Loader Lock Bits by SPM
- •Reading the Fuse and Lock Bits from Software
- •Preventing Flash Corruption
- •Simple Assembly Code Example for a Boot Loader
- •Fuse Bits
- •Latching of Fuses
- •Signature Bytes
- •Calibration Byte
- •Signal Names
- •Parallel Programming
- •Enter Programming Mode
- •Chip Erase
- •Programming the Flash
- •Programming the EEPROM
- •Reading the Flash
- •Reading the EEPROM
- •Programming the Lock Bits
- •Reading the Signature Bytes
- •Reading the Calibration Byte
- •Serial Downloading
- •Data Polling Flash
- •Data Polling EEPROM
- •AVR_RESET ($C)
- •PROG_ENABLE ($4)
- •PROG_COMMANDS ($5)
- •PROG_PAGELOAD ($6)
- •PROG_PAGEREAD ($7)
- •Data Registers
- •Reset Register
- •Programming Enable Register
- •Virtual Flash Page Read Register
- •Programming Algorithm
- •Entering Programming Mode
- •Leaving Programming Mode
- •Performing Chip Erase
- •Programming the Flash
- •Reading the Flash
- •Programming the EEPROM
- •Reading the EEPROM
- •Programming the Fuses
- •Programming the Lock Bits
- •Reading the Signature Bytes
- •Reading the Calibration Byte
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •DC Characteristics
- •External Clock Drive Waveforms
- •External Clock Drive
- •2-wire Serial Interface Characteristics
- •ADC Characteristics - Preliminary Data
- •External Data Memory Timing
- •Ordering Information
- •Packaging Information
Alternate Port Functions Most port pins have alternate functions in addition to being general digital I/Os. Figure 32 shows how the port pin control signals from the simplified Figure 29 can be overrid-
den by alternate functions. The overriding signals may not be present in all port pins, but the figure serves as a generic description applicable to all port pins in the AVR microcontroller family.
Figure 32. Alternate Port Functions(1)
|
|
PUOExn |
|
|
|
|
|
|
1 |
PUOVxn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
|
|
|
|
PUD |
|
|
|
|
|
|
|
|
|
|
|
DDOExn |
|
|
|
|
|
|
1 |
DDOVxn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
|
|
|
Q |
D |
|
|
|
|
|
|
DDxn |
|
|
|
|
|
|
|
Q CLR |
|
|
|
|
PVOExn |
|
|
|
WDx |
|
|
|
|
|
RESET |
|
||
|
|
|
|
|
|
||
|
|
PVOVxn |
|
|
|
RDx |
BUS |
|
1 |
|
|
|
|
|
|
Pxn |
|
|
|
|
Q |
D |
DATA |
|
0 |
|
|
|
|||
|
|
|
|
|
PORTxn |
|
|
|
|
DIEOExn |
|
|
Q CLR |
|
|
|
|
|
|
|
|
WPx |
|
|
1 |
DIEOVxn |
|
|
RESET |
|
|
|
|
|
|
|
RRx |
|
|
|
0 |
SLEEP |
|
|
|
|
|
|
|
|
|
|
|
||
|
|
|
SYNCHRONIZER |
RPx |
|
||
|
|
|
|
|
|
|
|
|
|
|
D SET |
Q |
D Q |
|
|
|
|
|
|
|
PINxn |
|
|
|
|
|
L CLR |
Q |
CLR Q |
|
|
|
|
|
|
|
|
clk I/O |
|
|
|
|
|
|
|
DIxn |
|
|
|
|
|
|
|
AIOxn |
|
PUOExn: |
Pxn PULL-UP OVERRIDE ENABLE |
|
PUD: |
|
PULLUP DISABLE |
|
|
PUOVxn: |
Pxn PULL-UP OVERRIDE VALUE |
|
WDx: |
|
WRITE DDRx |
|
|
DDOExn: |
Pxn DATA DIRECTION OVERRIDE ENABLE |
|
RDx: |
|
READ DDRx |
|
|
DDOVxn: |
Pxn DATA DIRECTION OVERRIDE VALUE |
|
RRx: |
|
READ PORTx REGISTER |
|
|
PVOExn: |
Pxn PORT VALUE OVERRIDE ENABLE |
|
WPx: |
|
WRITE PORTx |
|
|
PVOVxn: |
Pxn PORT VALUE OVERRIDE VALUE |
|
RPx: |
|
READ PORTx PIN |
|
|
DIEOExn: Pxn DIGITAL INPUT-ENABLE OVERRIDE ENABLE |
clk : |
|
I/O CLOCK |
|
|
||
DIEOVxn: Pxn DIGITAL INPUT-ENABLE OVERRIDE VALUE |
I/O |
|
DIGITAL INPUT PIN n ON PORTx |
|
|||
DIxn: |
|
|
|||||
SLEEP: |
SLEEP CONTROL |
|
AIOxn: |
ANALOG INPUT/OUTPUT PIN n ON PORTx |
Note: 1. WPx, WDx, RLx, RPx, and RDx are common to all pins within the same port. clkI/O,
SLEEP, and PUD are common to all ports. All other signals are unique for each pin.
Table 26 summarizes the function of the overriding signals. The pin and port indexes from Figure 32 are not shown in the succeeding tables. The overriding signals are gen-
erated internally in the modules having the alternate function.
66 ATmega128(L)
2467B–09/01
ATmega128(L)
Special Function IO Register –
SFIOR
2467B–09/01
Table 26. Generic Description of Overriding Signals for Alternate Functions.
Signal |
|
|
Name |
Full Name |
Description |
|
|
|
PUOE |
Pull-up |
If this signal is set, the pull-up enable is controlled by the |
|
Override Enable |
PUOV signal. If this signal is cleared, the pull-up is |
|
|
enabled when {DDxn, PORTxn, PUD} = 0b010. |
|
|
|
PUOV |
Pull-up |
If PUOE is set, the pull-up is enabled/disabled when |
|
Override Value |
PUOV is set/cleared, regardless of the setting of the |
|
|
DDxn, PORTxn, and PUD register bits. |
|
|
|
DDOE |
Data Direction |
If this signal is set, the Output Driver Enable is controlled |
|
Override Enable |
by the DDOV signal. If this signal is cleared, the Output |
|
|
driver is enabled by the DDxn register bit. |
|
|
|
DDOV |
Data Direction |
If DDOE is set, the Output Driver is enabled/disabled |
|
Override Value |
when DDOV is set/cleared, regardless of the setting of |
|
|
the DDxn register bit. |
|
|
|
PVOE |
Port Value |
If this signal is set and the Output Driver is enabled, the |
|
Override Enable |
port value is controlled by the PVOV signal. If PVOE is |
|
|
cleared, and the Output Driver is enabled, the port Value |
|
|
is controlled by the PORTxn register bit. |
|
|
|
PVOV |
Port Value |
If PVOE is set, the port value is set to PVOV, regardless |
|
Override Value |
of the setting of the PORTxn register bit. |
|
|
|
DIEOE |
Digital Input |
If this bit is set, the Digital Input Enable is controlled by |
|
Enable Override |
the DIEOV signal. If this signal is cleared, the Digital Input |
|
Enable |
Enable is determined by MCU-state (Normal Mode, Sleep |
|
|
Modes). |
|
|
|
DIEOV |
Digital Input |
If DIEOE is set, the Digital Input is enabled/disabled when |
|
Enable Override |
DIEOV is set/cleared, regardless of the MCU state |
|
Value |
(Normal Mode, Sleep Modes). |
|
|
|
DI |
Digital Input |
This is the Digital Input to alternate functions. In the |
|
|
figure, the signal is connected to the output of the schmitt |
|
|
trigger but before the synchronizer. Unless the Digital |
|
|
Input is used as a clock source, the module with the |
|
|
alternate function will use its own synchronizer. |
|
|
|
AIO |
Analog |
This is the Analog Input/output to/from alternate functions. |
|
Input/output |
The signal is connected directly to the pad, and can be |
|
|
used bidirectionally. |
|
|
|
The following subsections shortly describes the alternate functions for each port, and relates the overriding signals to the alternate function. Refer to the alternate function description for further details.
Bit |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
|
|
TSM |
– |
– |
ADHSM |
ACME |
PUD |
PSR0 |
PSR321 |
SFIOR |
Read/Write |
R/W |
R |
R |
R/W |
R/W |
R/W |
R/W |
R/W |
|
Initial value |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
|
67
• Bit 2 - 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” on page 61 for more details about this feature.
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.
Table 27. Port A Pins Alternate Functions
Port Pin |
Alternate Function |
|
|
PA7 |
AD7 (External memory interface address and data bit 7) |
|
|
PA6 |
AD6 (External memory interface address and data bit 6) |
|
|
PA5 |
AD5 (External memory interface address and data bit 5) |
|
|
PA4 |
AD4 (External memory interface address and data bit 4) |
|
|
PA3 |
AD3 (External memory interface address and data bit 3) |
|
|
PA2 |
AD2 (External memory interface address and data bit 2) |
|
|
PA1 |
AD1 (External memory interface address and data bit 1) |
|
|
PA0 |
AD0 (External memory interface address and data bit 0) |
|
|
Table 28 and Table 29 relates the alternate functions of Port A to the overriding signals shown in Figure 32 on page 66.
Table 28. Overriding Signals for Alternate Functions in PA7..PA4
Signal |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Name |
|
PA7/AD7 |
PA6/AD6 |
PA5/AD5 |
PA4/AD4 |
||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|||||||||||||||||||||||||||||||
PUOE |
|
|
SRE |
SRE |
SRE |
SRE |
|||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PUOV |
|
|
|
|
|
| ADA(1)) • |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
~(WR |
~(WR | ADA) • |
~(WR | ADA) • |
~(WR | ADA) • |
||||||||||||||||||||||||||||||||
|
|
PORTA7 • |
PUD |
|
PORTA6 • |
PUD |
|
PORTA5 • |
PUD |
|
PORTA4 • |
PUD |
|
||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||||||||||||
DDOE |
|
|
SRE |
|
SRE |
|
SRE |
|
SRE |
||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||||||||
DDOV |
|
|
|
|
| ADA |
|
|
|
| ADA |
|
|
|
| ADA |
|
|
|
| ADA |
||||||||||||||||||||
WR |
WR |
WR |
WR |
||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|||||||||||||||||||||||||||||||
PVOE |
|
|
SRE |
SRE |
SRE |
SRE |
|||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|||||||||||||||||||||||||||||||
PVOV |
|
|
A7 • ADA | D7 |
A6 • ADA | D6 |
A5 • ADA | D5 |
A4 • ADA | D4 |
|||||||||||||||||||||||||||||||
|
|
OUTPUT • |
WR |
|
OUTPUT • |
WR |
|
OUTPUT • |
WR |
|
OUTPUT • |
WR |
|
||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
DIEOE |
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
DIEOV |
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
||||||||||||||||||||||||||||||||
DI |
|
D7 INPUT |
D6 INPUT |
D5 INPUT |
D4 INPUT |
||||||||||||||||||||||||||||||||
|
|
|
|
|
|
||||||||||||||||||||||||||||||||
AIO |
|
– |
– |
– |
– |
||||||||||||||||||||||||||||||||
|
|
|
|
|
|
||||||||||||||||||||||||||||||||
Note: |
1. ADA is short for ADdress Active and represents the time when address is output. See |
||||||||||||||||||||||||||||||||||||
|
|
|
“External Memory Interface” on page 24 for details. |
|
|
|
|
|
|
|
|
|
68 ATmega128(L)
2467B–09/01
ATmega128(L)
Table 29. Overriding Signals for Alternate Functions in PA3..PA0
Signal |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Name |
PA3/AD3 |
|
PA2/AD2 |
|
PA1/AD1 |
|
PA0/AD0 |
|||||||||||||||||||||||||||||
|
|
|
|
|
|
|||||||||||||||||||||||||||||||
PUOE |
|
SRE |
SRE |
SRE |
SRE |
|||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PUOV |
|
|
|
|
| ADA) • |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
~(WR |
~(WR | ADA) • |
~(WR | ADA) • |
~(WR | ADA) • |
||||||||||||||||||||||||||||||||
|
PORTA3 • |
PUD |
|
PORTA2 • |
PUD |
|
PORTA1 • |
PUD |
|
PORTA0 • |
PUD |
|
||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
||||||||||||||||||||||||||||
DDOE |
|
SRE |
|
SRE |
|
SRE |
|
SRE |
||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||||||||
DDOV |
|
|
|
| ADA |
|
|
|
| ADA |
|
|
|
| ADA |
|
|
|
| ADA |
||||||||||||||||||||
WR |
WR |
WR |
WR |
|||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|||||||||||||||||||||||||||||||
PVOE |
|
SRE |
SRE |
SRE |
SRE |
|||||||||||||||||||||||||||||||
|
|
|
|
|
||||||||||||||||||||||||||||||||
PVOV |
A3 • ADA | D3 |
A2• ADA | D2 |
A1 • ADA | D1 |
A0 • ADA | D0 |
||||||||||||||||||||||||||||||||
|
OUTPUT • |
WR |
|
OUTPUT • |
WR |
|
OUTPUT • |
WR |
|
OUTPUT • |
WR |
|
||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
DIEOE |
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
DIEOV |
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
||||||||||||||||||||||||||||
DI |
|
D3 INPUT |
|
D2 INPUT |
|
D1 INPUT |
|
D0 INPUT |
||||||||||||||||||||||||||||
|
|
|
|
|
||||||||||||||||||||||||||||||||
AIO |
– |
– |
– |
– |
||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Alternate Functions of Port B The Port B pins with alternate functions are shown in Table 30.
Table 30. Port B Pins Alternate Functions
Port Pin |
|
Alternate Functions |
||
|
|
|||
PB7 |
OC2/OC1C(1) (Output Compare and PWM Output for Timer/Counter2 or Output |
|||
Compare and PWM Output C for Timer/Counter1) |
||||
|
||||
|
|
|
||
PB6 |
|
OC1B (Output Compare and PWM Output B for Timer/Counter1) |
||
|
|
|
||
PB5 |
|
OC1A (Output Compare and PWM Output A for Timer/Counter1) |
||
|
|
|
||
PB4 |
|
OC0 (Output Compare and PWM Output for Timer/Counter0) |
||
|
|
|
||
PB3 |
|
MISO (SPI Bus Master Input/Slave Output) |
||
|
|
|
||
PB2 |
|
MOSI (SPI Bus Master Output/Slave Input) |
||
|
|
|
||
PB1 |
|
SCK (SPI Bus Serial Clock) |
||
|
|
|
|
|
PB0 |
|
|
(SPI Slave Select input) |
|
SS |
||||
|
|
|||
Note: 1. |
OC1C not applicable in ATmega103 compatibility mode. |
The alternate pin configuration is as follows:
• OC2/OC1C, Bit 7
OC2, Output Compare match output: The PB7 pin can serve as an external output for the Timer/Counter2 output compare. The pin has to be configured as an output (DDB7 set “one”) to serve this function. The OC2 pin is also the output pin for the PWM mode timer function.
OC1C, Output Compare matchC output: The PB7 pin can serve as an external output for the Timer/Counter1 output compareC. The pin has to be configured as an output (DDB7 set (one)) to serve this function. The OC1C pin is also the output pin for the PWM mode timer function.
69
2467B–09/01
• OC1B, Bit 6
OC1B, Output Compare matchB output: The PB6 pin can serve as an external output for the Timer/Counter1 output compareB. The pin has to be configured as an output (DDB6 set (one)) to serve this function. The OC1B pin is also the output pin for the PWM mode timer function.
• OC1A, Bit 5
OC1A, Output Compare matchA output: The PB5 pin can serve as an external output for the Timer/Counter1 output compareA. The pin has to be configured as an output (DDB5 set (one)) to serve this function. The OC1A pin is also the output pin for the PWM mode timer function.
• OC0, Bit 4
OC0, Output Compare match output: The PB4 pin can serve as an external output for the Timer/Counter0 output compare. The pin has to be configured as an output (DDB4 set (one)) to serve this function. The OC0 pin is also the output pin for the PWM mode timer function.
• MISO - Port B, Bit 3
MISO: Master data input, slave data output pin for SPI channel. When the SPI is enabled as a master, this pin is configured as an input regardless of the setting of DDB3. When the SPI is enabled as a slave, the data direction of this pin is controlled by DDB3. When the pin is forced to be an input, the pull-up can still be controlled by the PORTB3 bit.
• MOSI - Port B, Bit 2
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. When the SPI is enabled as a slave, this pin is configured as an input regardless of the setting of DDB1. When the SPI is enabled as a master, the data direction of this pin is controlled by DDB1. When the pin is forced to be an input, the pull-up can still be controlled by the PORTB1 bit.
• SS - Port B, Bit 0
SS: Slave port select input. When the SPI is enabled as a slave, this pin is configured as an input regardless of the setting of DDB0. As a slave, the SPI is activated when this pin is driven low. When the SPI is enabled as a master, the data direction of this pin is controlled by DDB0. When the pin is forced to be an input, the pull-up can still be controlled by the PORTB0 bit.
Table 31 and Table 32 relate the alternate functions of Port B to the overriding signals shown in Figure 32 on page 66. SPI MSTR INPUT and SPI SLAVE OUTPUT constitute
the MISO signal, while MOSI is divided into SPI MSTR OUTPUT and SPI SLAVE INPUT.
70 ATmega128(L)
2467B–09/01
ATmega128(L)
Table 31. Overriding Signals for Alternate Functions in PB7..PB4
Signal Name |
PB7/OC2/OC1C |
PB6/OC1B |
PB5/OC1A |
PB4/OC0 |
|
|
|
|
|
PUOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
PUOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
PVOE |
OC2/OC1C ENABLE(1) |
OC1B ENABLE |
OC1A ENABLE |
OC0 ENABLE |
PVOV |
OC2/OC1C(1) |
OC1B |
OC1A |
OC0B |
DIEOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
DIEOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DI |
– |
– |
– |
– |
|
|
|
|
|
AIO |
– |
– |
– |
– |
|
|
|
|
|
Note: 1. See “Output Compare Modulator (OCM1C2)” on page 155 for details. OC1C does not exist in ATmega103 compatibility mode.
Table 32. Overriding Signals for Alternate Functions in PB3..PB0
Signal |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Name |
PB3/MISO |
PB2/MOSI |
PB1/SCK |
PB0/SS |
|
|
|
|
|||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||
PUOE |
SPE • MSTR |
SPE • |
|
|
|
|
|
SPE • |
|
|
|
|
SPE • |
|
|
|
|
|
|
||||||
MSTR |
MSTR |
MSTR |
|||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||
PUOV |
PORTB3 • |
|
|
|
PORTB2 • |
|
|
|
|
PORTB1 • |
|
|
|
PORTB0 • |
|
|
|
||||||||
PUD |
PUD |
PUD |
PUD |
||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||
DDOE |
SPE • MSTR |
SPE • |
|
|
|
|
SPE • |
|
|
|
SPE • |
|
|
|
|
|
|||||||||
MSTR |
MSTR |
MSTR |
|||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DDOV |
0 |
|
|
|
|
0 |
|
|
|
|
|
0 |
|
|
|
|
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||
PVOE |
SPE • |
|
|
|
SPE • MSTR |
SPE • MSTR |
0 |
|
|
|
|
|
|
|
|
||||||||||
MSTR |
|
|
|
|
|
|
|
||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||||
PVOV |
SPI SLAVE OUTPUT |
SPI MSTR OUTPUT |
SCK OUTPUT |
0 |
|
|
|
|
|
|
|
|
|||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DIEOE |
0 |
|
|
|
|
0 |
|
|
|
|
|
0 |
|
|
|
|
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DIEOV |
0 |
|
|
|
|
0 |
|
|
|
|
|
0 |
|
|
|
|
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||||||||||||||||
DI |
SPI MSTR INPUT |
SPI SLAVE INPUT |
SCK INPUT |
SPI |
|
|
|
|
|||||||||||||||||
SS |
|||||||||||||||||||||||||
|
|
|
|
|
|||||||||||||||||||||
AIO |
– |
– |
– |
– |
|||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71
2467B–09/01