Starting Electronics Needs Your Help!
It is that time of the year when we need to pay for web hosting and buy new components and equipment for new tutorials. You can help by making a donation. Contribute to this website by clicking the Donate button. The total will be updated once daily. (You may need to clear your browser cache to see the updates.)
Target Amount: $2000
Amount Raised: $1139
Top Donor: C.C. $100
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.
The image below shows the ATtiny2313 DIP package with the alternate pin functions labelled:
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.
PA2 (pin 1) of the ATtiny2313 microcontroller has two alternate functions – it can be used as a RESET pin or as a 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.
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.
Outputs the system clock on this pin when the CKOUT fuse bit is programmed.
INT0 and INT1 are both external interrupt sources to the microcontroller.
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.
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.
AIN0 and AIN1 are the input pins for the analog comparator. AIN0 is the positive input pin. AIN1 is the negative input pin.
PCINT pins can serve as an external interrupt source that generates an interrupt if the logic level on the pin changes (toggles).
The USI can be used for two-wire and 3-wire serial communication such as 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.
The USI can also be used for several alternative functions, such as: