- •Features
- •Pin Configurations
- •Overview
- •Block Diagram
- •Pin Descriptions
- •Port A (PA2..PA0)
- •Port B (PB7..PB0)
- •Port D (PD6..PD0)
- •RESET
- •XTAL1
- •XTAL2
- •Disclaimer
- •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
- •Atomic Byte Programming
- •Split Byte Programming
- •Erase
- •Write
- •I/O Memory
- •General Purpose I/O Registers
- •Clock Systems and their Distribution
- •Clock Sources
- •Default Clock Source
- •Crystal Oscillator
- •External Clock
- •Idle Mode
- •Power-down Mode
- •Standby Mode
- •Analog Comparator
- •Brown-out Detector
- •Internal Voltage Reference
- •Watchdog Timer
- •Port Pins
- •Resetting the AVR
- •Reset Sources
- •Power-on Reset
- •External Reset
- •Brown-out Detection
- •Watchdog Reset
- •Watchdog Timer
- •Interrupts
- •I/O-Ports
- •Introduction
- •Configuring the Pin
- •Toggling the Pin
- •Reading the Pin Value
- •Alternate Port Functions
- •Alternate Functions of Port A
- •Alternate Functions of Port B
- •Alternate Functions of Port D
- •Register Description for I/O-Ports
- •External Interrupts
- •8-bit Timer/Counter0 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
- •Internal Clock Source
- •Prescaler Reset
- •External Clock Source
- •16-bit Timer/Counter1
- •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
- •USART
- •Overview
- •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
- •Overview
- •Functional Descriptions
- •Three-wire Mode
- •SPI Slave Operation Example
- •Two-wire Mode
- •Start Condition Detector
- •Alternative USI Usage
- •4-bit Counter
- •12-bit Timer/Counter
- •Software Interrupt
- •Analog Comparator
- •debugWIRE On-chip Debug System
- •Features
- •Overview
- •Physical Interface
- •Software Break Points
- •Limitations of debugWIRE
- •debugWIRE Related Register in I/O Memory
- •Performing a Page Write
- •Reading the Fuse and Lock Bits from Software
- •Preventing Flash Corruption
- •Fuse Bits
- •Latching of Fuses
- •Signature Bytes
- •Calibration Byte
- •Page Size
- •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
- •Electrical Characteristics
- •Absolute Maximum Ratings*
- •DC Characteristics
- •External Clock Drive Waveforms
- •External Clock Drive
- •Active Supply Current
- •Idle Supply Current
- •Power-down Supply Current
- •Standby Supply Current
- •Pin Pull-up
- •Pin Driver Strength
- •Internal Oscillator Speed
- •Register Summary
- •Instruction Set Summary
- •Ordering Information
- •Packaging Information
- •Errata
- •ATtiny2313 Rev B
- •ATtiny2313 Rev A
- •Changes from Rev. 2514F-08/04 to Rev. 2514G-10/04
- •Changes from Rev. 2514F-08/04 to Rev. 2514G-10/04
- •Changes from Rev. 2514E-04/04 to Rev. 2514F-08/04
- •Changes from Rev. 2514D-03/04 to Rev. 2514E-04/04
- •Changes from Rev. 2514C-12/03 to Rev. 2514D-03/04
- •Changes from Rev. 2514B-09/03 to Rev. 2514C-12/03
- •Changes from Rev. 2514A-09/03 to Rev. 2514B-09/03
- •Table of Contents
Alternate Port Functions Most port pins have alternate functions in addition to being general digital I/Os. Figure 25 shows how the port pin control signals from the simplified Figure 22 can be overridden 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 25. Alternate Port Functions(1)
|
PUOExn |
|
|
|
|
|
|
|
1 |
PUOVxn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
|
|
|
|
|
PUD |
|
|
|
|
|
|
|
|
|
|
|
|
DDOExn |
|
|
|
|
|
|
|
1 |
DDOVxn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
|
|
|
Q |
D |
|
|
|
|
|
|
|
DDxn |
|
|
|
|
|
|
|
|
Q CLR |
|
|
|
|
|
PVOExn |
|
|
RESET |
WDx |
|
|
|
|
|
|
|
|
|
|||
|
PVOVxn |
|
|
|
|
RDx |
|
|
|
|
|
|
|
|
|
BUS |
|
Pxn |
|
|
|
|
|
1 |
|
|
1 |
|
|
|
|
|
|
|
|
0 |
|
|
|
Q |
D |
0 |
|
DATA |
|
|
|
|
PORTxn |
|
|
||
|
DIEOExn |
|
|
Q CLR |
|
|
PTOExn |
|
|
|
|
|
|
|
|
WPx |
|
1 |
DIEOVxn |
|
|
RESET |
|
WRx |
|
|
|
|
|
|
|
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 |
PUOVxn: |
Pxn PULL-UP OVERRIDE VALUE |
DDOExn: |
Pxn DATA DIRECTION OVERRIDE ENABLE |
DDOVxn: |
Pxn DATA DIRECTION OVERRIDE VALUE |
PVOExn: |
Pxn PORT VALUE OVERRIDE ENABLE |
PVOVxn: |
Pxn PORT VALUE OVERRIDE VALUE |
DIEOExn: |
Pxn DIGITAL INPUT-ENABLE OVERRIDE ENABLE |
DIEOVxn: |
Pxn DIGITAL INPUT-ENABLE OVERRIDE VALUE |
SLEEP: |
SLEEP CONTROL |
PTOExn: |
Pxn, PORT TOGGLE OVERRIDE ENABLE |
PUD: |
PULLUP DISABLE |
WDx: |
WRITE DDRx |
RDx: |
READ DDRx |
RRx: |
READ PORTx REGISTER |
WRx: |
WRITE PORTx |
RPx: |
READ PORTx PIN |
WPx: |
WRITE PINx |
clk : |
I/O CLOCK |
I/O |
DIGITAL INPUT PIN n ON PORTx |
DIxn: |
|
AIOxn: |
ANALOG INPUT/OUTPUT PIN n ON PORTx |
Note: 1. WRx, 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. All other signals are unique for each pin.
Table 23 summarizes the function of the overriding signals. The pin and port indexes from Figure 25 are not shown in the succeeding tables. The overriding signals are generated internally in the modules having the alternate function.
50 ATtiny2313/V
2543H–AVR–02/05
|
|
|
|
|
ATtiny2313/V |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Table 23. Generic Description of Overriding Signals for Alternate Functions |
|||
|
|
||||
|
|
|
|
|
|
|
|
Signal Name |
Full Name |
Description |
|
|
|
|
|
|
|
|
|
PUOE |
Pull-up Override |
If this signal is set, the pull-up enable is controlled by the |
|
|
|
|
Enable |
PUOV signal. If this signal is cleared, the pull-up is |
|
|
|
|
|
enabled when {DDxn, PORTxn, PUD} = 0b010. |
|
|
|
|
|
|
|
|
|
PUOV |
Pull-up Override |
If PUOE is set, the pull-up is enabled/disabled when |
|
|
|
|
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. |
|
|
|
|
|
|
|
|
|
PTOE |
Port Toggle |
If PTOE is set, the PORTxn Register bit is inverted. |
|
|
|
|
Override Enable |
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
mode). |
|
|
|
|
|
|
|
|
|
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 mode). |
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
Input/Output |
functions. The signal is connected directly to the pad, and |
|
|
|
|
|
can be used bi-directionally. |
|
|
|
|
|
|
|
The following subsections shortly describe the alternate functions for each port, and relate the overriding signals to the alternate function. Refer to the alternate function description for further details.
51
2543H–AVR–02/05
MCU Control Register –
MCUCR
Alternate Functions of Port A
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bit |
7 |
6 |
|
5 |
4 |
3 |
2 |
1 |
0 |
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PUD |
SM1 |
|
|
SE |
SM0 |
ISC11 |
ISC10 |
ISC01 |
ISC00 |
MCUCR |
|
Read/Write |
R/W |
R/W |
|
R/W |
R/W |
R/W |
R/W |
R/W |
R/W |
|
||
Initial Value |
0 |
0 |
|
0 |
0 |
0 |
0 |
0 |
0 |
|
• Bit 7 – 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 46 for more details about this feature.
The Port A pins with alternate functions are as shown in Table 5.
Table 24. Port A Pins Alternate Functions
Port Pin |
Alternate Function |
|
|
PA2 |
RESET, dW |
|
|
PA1 |
XTAL2 |
|
|
PA0 |
XTAL1 |
|
|
Alternate Functions of Port B The Port B pins with alternate functions are shown in Table 25.
Table 25. Port B Pins Alternate Functions
Port Pin Alternate Functions
PB7 USCK/SCL/PCINT7
PB6 DO/PCINT6
PB5 DI/SDA/PCINT5
PB4 OC1B/PCINT4
PB3 OC1A/PCINT3
PB2 OC0A/PCINT2
PB1 AIN1/PCINT1
PB0 AIN0/PCINT0
The alternate pin configuration is as follows:
• USCK/SCL/PCINT7 - Port B, Bit 7
USCK: Three-wire mode Universal Serial Interface Clock.
SCL: Two-wire mode Serial Clock for USI Two-wire mode.
PCINT7: Pin Change Interrupt source 7. The PB7 pin can serve as an external interrupt source.
• DO/PCINT6 - Port B, Bit 6
DO: Three-wire mode Universal Serial Interface Data output. Three-wire mode Data output overrides PORTB6 value and it is driven to the port when data direction bit DDB6 is set (one). However the PORTB6 bit still controls the pull-up enabling pull-up, if direction is input and PORTB6 is set (one).
PCINT6: Pin Change Interrupt Source 6. The PB6 pin can serve as an external interrupt source.
• DI/SDA/PCINT5 - Port B, Bit 5
52 ATtiny2313/V
2543H–AVR–02/05
ATtiny2313/V
DI: Three-wire mode Universal Serial Interface Data input. Three-wire mode does not override normal port functions, so pin must be configured as an input. SDA: Two-wire mode Serial Interface Data.
PCINT5: Pin Change Interrupt Source 5. The PB5 pin can serve as an external interrupt source.
• OC1B/PCINT4 – Port B, Bit 4
OC1B: Output Compare Match B output: The PB4 pin can serve as an external output for the Timer/Counter1 Output Compare B. 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.
PCINT4: Pin Change Interrupt Source 4. The PB4 pin can serve as an external interrupt source.
• OC1A/PCINT3 – Port B, Bit 3
OC1A: Output Compare Match A output: The PB3 pin can serve as an external output for the Timer/Counter1 Output Compare A. The pin has to be configured as an output (DDB3 set (one)) to serve this function. The OC1A pin is also the output pin for the PWM mode timer function.
PCINT3: Pin Change Interrupt Source 3: The PB3 pin can serve as an external interrupt source.
• OC0A/PCINT2 – Port B, Bit 2
OC0A: Output Compare Match A output. The PB2 pin can serve as an external output for the Timer/Counter0 Output Compare A. The pin has to be configured as an output (DDB2 set (one)) to serve this function. The OC0A pin is also the output pin for the PWM mode timer function.
PCINT2: Pin Change Interrupt Source 2. The PB2 pin can serve as an external interrupt source.
• AIN1/PCINT1 – Port B, Bit 1
AIN1: Analog Comparator Negative input. Configure the port pin as input with the internal pull-up switched off to avoid the digital port function from interfering with the function of the analog comparator.
PCINT1: Pin Change Interrupt Source 1. The PB1 pin can serve as an external interrupt source.
• AIN0/PCINT0 – Port B, Bit 0
AIN0: Analog Comparator Positive input. Configure the port pin as input with the internal pull-up switched off to avoid the digital port function from interfering with the function of the Analog Comparator.
PCINT0: Pin Change Interrupt Source 0. The PB0 pin can serve as an external interrupt source.
Table 26 and Table 27 relate the alternate functions of Port B to the overriding signals shown in Figure 25 on page 50. SPI MSTR INPUT and SPI SLAVE OUTPUT constitute the MISO signal, while MOSI is divided into SPI MSTR OUTPUT and SPI SLAVE INPUT.
53
2543H–AVR–02/05
Table 26. Overriding Signals for Alternate Functions in PB7..PB4
Signal |
PB7/USCK/ |
|
PB5/SDA/ |
PB4/OC1B/ |
||||||
Name |
SCL/PCINT7 |
PB6/DO/PCINT6 |
DI/PCINT5 |
PCINT4 |
||||||
|
|
|
|
|
|
|
|
|
|
|
PUOE |
0 |
|
|
0 |
0 |
|
|
|
0 |
|
|
|
|
|
|
|
|
|
|
|
|
PUOV |
0 |
|
|
0 |
0 |
|
|
|
0 |
|
|
|
|
|
|
||||||
DDOE |
USI_TWO_WIRE |
0 |
USI_TWO_WIRE |
0 |
||||||
|
|
|
|
|
|
|
|
|
||
DDOV |
(USI_SCL_HOLD |
0 |
|
|
+ |
|
|
0 |
||
(SDA |
PORTB5)• |
|||||||||
|
+ |
|
|
|
DDRB5 |
|
||||
|
PORTB7)•DDB7 |
|
|
|||||||
|
|
|
|
|
||||||
PVOE |
USI_TWO_WIRE |
USI_THREE_WIRE |
USI_TWO_WIRE |
OC1B_PVOE |
||||||
|
• DDRB7 |
|
• DDRB5 |
|
||||||
|
|
|
|
|
|
|
|
|
|
|
PVOV |
0 |
|
|
DO |
0 |
|
|
|
0OC1B_PVOV |
|
|
|
|
|
|
|
|
|
|||
PTOE |
USI_PTOE |
0 |
0 |
|
|
|
0 |
|||
|
|
|
|
|
||||||
DIEOE |
(PCINT7•PCIE) |
(PCINT6•PCIE) |
(PCINT5•PCIE) + |
(PCINT4•PCIE) |
||||||
|
+USISIE |
|
USISIE |
|
||||||
|
|
|
|
|
|
|
|
|
|
|
DIEOV |
1 |
|
|
1 |
1 |
|
|
|
1 |
|
|
|
|
|
|
||||||
DI |
PCINT7 INPUT |
PCINT6 INPUT |
PCINT5 INPUT |
PCINT4 INPUT |
||||||
|
USCK INPUT SCL |
|
SDA INPUT |
|
||||||
|
INPUT |
|
DI INPUT |
|
||||||
|
|
|
|
|
|
|||||
|
|
|
|
|
||||||
AIO |
– |
– |
– |
– |
||||||
|
|
|
|
|
|
|
|
|
|
|
Table 27. Overriding Signals for Alternate Functions in PB3..PB0
Signal |
PB3/OC1A/ |
PB2/OC0A/ |
PB1/AIN1/ |
PB0/AIN0/ |
Name |
PCINT3 |
PCINT2 |
PCINT1 |
PCINT0 |
|
|
|
|
|
PUOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
PUOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
DDOV |
0 |
0 |
0 |
0 |
|
|
|
|
|
PVOE |
OC1A_PVOE |
OC0A_PVOE |
0 |
0 |
|
|
|
|
|
PVOV |
OC1A_PVOV |
OC0A_PVOV |
0 |
0 |
|
|
|
|
|
PTOE |
0 |
0 |
0 |
0 |
|
|
|
|
|
DIEOE |
(PCINT3 • PCIE) |
(PCINT2 • PCIE) |
(PCINT1 • PCIE) |
(PCINT0 • PCIE) |
|
|
|
|
|
DIEOV |
1 |
1 |
1 |
1 |
|
|
|
|
|
DI |
PCINT7 INPUT |
PCINT6 INPUT |
PCINT5 INPUT |
PCINT4 INPUT |
|
|
|
|
|
AIO |
– |
– |
AIN1 |
AIN0 |
|
|
|
|
|
54 ATtiny2313/V
2543H–AVR–02/05