ATtiny2313 Alternate Pin Functions

Created on: 22 February 2013

Part 5 of the ATtiny2313 Tutorial

An overview of the alternate pin functions of the ATtiny2313 microcontroller and the internal peripherals that connect to them.

The purpose of this part of the tutorial is to get familiar with the internal peripherals that connect to external pins of the ATtiny2313 microcontroller. There are also internal peripherals that do not connect to pins of the ATtiny2313, such as the watchdog timer and EEPROM.

Each peripheral will be covered individually in detail and include software examples later in this tutorial series. The information below just shows what peripherals are available and which pins of the microcontroller they use.

Alternate Pin Functions

The image below shows the ATtiny2313 DIP package with the alternate pin functions labelled:

ATtiny2313 alternate pin functions
ATtiny2313 Alternate Pin Functions

Every port pin of the ATtiny2313 can be used as an I/O (input / output) pin. When we refer to an alternate function of a pin, we are referring to a function other than I/O (alternate to I/O). We will now look at what each of these alternate functions is.

RESET / dW – Reset and debugWIRE

PA2 (pin 1) of the ATtiny2313 microcontroller has two alternate functions – it can be used as a RESET pin or as a debugWIRE pin.

ATtiny2313 reset and debugWIRE pin


Pin 1 (PA2) can be used as an external active low reset pin. A fuse bit in the AVR must be programmed in order to enable this pin as a reset pin (RSTDISBL fuse).

Older microcontrollers usually require an external reset circuit on a dedicated reset pin to reset the microcontroller when power to the microcontroller circuit is switched on. This is not so with AVR microcontrollers – they have an internal reset circuit that holds them in reset at power up until the power supply is stable.


Pin 1 (PA2) can be used in debugWIRE (dW) mode. An internal fuse of the ATtiny2313 must be programmed to enable debugWIRE mode (DWEN fuse). The fuse is programmed by using a tool such as the AVR Dragon.

Once debugWIRE mode is enabled, an external tool (e.g. AVR dragon) can be used in conjunction with software (e.g. Atmel Studio) to debug a C program running on the AVR and single-step through the source code.


The USART can act as a UART using RXD and TXD, or act as a USART using RXD, TXD and XCK.

ATtiny2313 USART pins TXD and RXD

XTAL1 & XTAL2 – External Crystal

The XTAL1 and XTAL2 pins can be connected to an external crystal to generate a more accurate CPU clock frequency (and a frequency from a wider range) than the default internal R/C oscillator.

XTAL1 can be connected to an external oscillator and used as a source for the CPU clock frequency.

ATtiny2313 crystal pins XTAL1 and XTAL2

CKOUT – System Clock Output

Outputs the system clock on this pin when the CKOUT fuse bit is programmed.

ATtiny2313 CKOUT pin

INT0 and INT1 – External Interrupt Pins

INT0 and INT1 are both external interrupt sources to the microcontroller.

INT0 and INT1 interrupt pins

T0, OC0A & OC0B – 8-bit Timer / Counter 0

An 8-bit timer/counter with PWM. T0 is an input for an external clock source. OC0A and OC0B are output pins from the timer/counter on which a frequency can be output – e.g. a PWM frequency.

ATtiny2313 timer 0 pins

T1, OC1A, OC1B & ICP – 16-bit Timer / Counter 1

Timer/counter 1 is a 16-bit timer/counter with PWM. The T1 input is an input for an external clock source. OC1A and OC1B are two independent outputs from the timer counter that can each output a frequency. ICP is the input capture pin for timer/counter 1.

ATtiny2313 timer 1 pins

AIN0 & AIN1 – Analog Comparator

AIN0 and AIN1 are the input pins for the analog comparator. AIN0 is the positive input pin. AIN1 is the negative input pin.

ATtiny2313 analog comparator pins

PCINT0 to PCINT7 – Pin Change Interrupt

PCINT pins can serve as an external interrupt source that generates an interrupt if the logic level on the pin changes (toggles).

PCINT pins on the ATtiny2313

Universal Serial Interface (USI)

The USI can be used for two-wire and 3-wire serial communication such as SPI and TWI.

ATtiny2313 USI pins for SPI and TWI


Three-wire mode of the USI is compatible with SPI (Serial Peripheral Interface), but does not have the SS (Slave Select) pin.


In two-wire mode, the SCL and SDA pins are used. Two-wire mode is TWI and I2C compatible.

Alternative USI Usage

The USI can also be used for several alternative functions, such as:

  • Half-duplex Asynchronous Data Transfer
  • 4-bit Counter
  • 12-bit Timer/Counter
  • Edge Triggered External Interrupt
  • Software Interrupt