Introduction to Attiny84
The Attiny84 is a low-power, high-performance microcontroller that belongs to Atmel’s AVR family. It is an 8-bit microcontroller with 8KB of flash memory, 512 bytes of EEPROM, and 512 bytes of internal SRAM. The Attiny84 operates at a maximum frequency of 20MHz and offers a wide range of peripherals, making it suitable for a variety of embedded applications.
Key Features of Attiny84
- 8KB of in-system programmable flash memory
- 512 bytes of EEPROM
- 512 bytes of internal SRAM
- 12 general-purpose I/O lines
- 32 general-purpose working registers
- One 8-bit timer/counter with compare modes
- One 16-bit timer/counter with compare modes
- Universal Serial Interface (USI) supporting SPI and I2C
- 10-bit ADC with 8 channels
- Programmable Watchdog Timer with internal oscillator
- Power-on Reset and programmable Brown-out Detection
- Internal calibrated oscillator
Attiny84 Pin Configuration
The Attiny84 comes in a 14-pin PDIP (Plastic Dual Inline Package) or 14-pin SOIC (Small Outline Integrated Circuit) package. Here’s a detailed look at the pin configuration:
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply |
2 | PB0 | Port B, bit 0 (PCINT8/XTAL1/CLKI) |
3 | PB1 | Port B, bit 1 (PCINT9/XTAL2) |
4 | PB3 | Port B, bit 3 (PCINT11/RESET/ADC3) |
5 | PB2 | Port B, bit 2 (PCINT10/INT0/ADC2) |
6 | PA7 | Port A, bit 7 (PCINT7/ADC7/MOSI/DI/SDA) |
7 | PA6 | Port A, bit 6 (PCINT6/ADC6/MISO/DO) |
8 | PA5 | Port A, bit 5 (PCINT5/OC0B/ADC5/T0/USCK/SCL) |
9 | PA4 | Port A, bit 4 (PCINT4/T1/ADC4/SCK/USCK) |
10 | PA3 | Port A, bit 3 (PCINT3/ADC3) |
11 | PA2 | Port A, bit 2 (PCINT2/AIN1/ADC2) |
12 | PA1 | Port A, bit 1 (PCINT1/AIN0/ADC1) |
13 | PA0 | Port A, bit 0 (PCINT0/AREF/ADC0) |
14 | GND | Ground |
Pin Functions
-
VCC: This pin is used to supply power to the microcontroller. The Attiny84 operates at a voltage range of 1.8V to 5.5V.
-
GND: This pin is connected to the ground of the circuit.
-
Port B (PB0-PB3): These pins serve as general-purpose I/O lines and can be configured as inputs or outputs. They also have alternate functions:
- PB0 (PCINT8/XTAL1/CLKI): This pin can be used as an external clock input or as a pin change interrupt (PCINT8).
- PB1 (PCINT9/XTAL2): This pin can be used as an external clock output or as a pin change interrupt (PCINT9).
- PB2 (PCINT10/INT0/ADC2): This pin can be used as an external interrupt (INT0), analog input (ADC2), or pin change interrupt (PCINT10).
-
PB3 (PCINT11/RESET/ADC3): This pin serves as the reset pin for the microcontroller. It can also be used as an analog input (ADC3) or pin change interrupt (PCINT11).
-
Port A (PA0-PA7): These pins serve as general-purpose I/O lines and have alternate functions:
- PA0 (PCINT0/AREF/ADC0): This pin can be used as an analog reference voltage (AREF), analog input (ADC0), or pin change interrupt (PCINT0).
- PA1 (PCINT1/AIN0/ADC1): This pin can be used as an analog comparator negative input (AIN0), analog input (ADC1), or pin change interrupt (PCINT1).
- PA2 (PCINT2/AIN1/ADC2): This pin can be used as an analog comparator positive input (AIN1), analog input (ADC2), or pin change interrupt (PCINT2).
- PA3 (PCINT3/ADC3): This pin can be used as an analog input (ADC3) or pin change interrupt (PCINT3).
- PA4 (PCINT4/T1/ADC4/SCK/USCK): This pin can be used as a timer/counter1 input (T1), analog input (ADC4), SPI clock (SCK), USI clock (USCK), or pin change interrupt (PCINT4).
- PA5 (PCINT5/OC0B/ADC5/T0/USCK/SCL): This pin can be used as a timer/counter0 output compare match B (OC0B), analog input (ADC5), timer/counter0 input (T0), USI clock (USCK), I2C clock (SCL), or pin change interrupt (PCINT5).
- PA6 (PCINT6/ADC6/MISO/DO): This pin can be used as an analog input (ADC6), SPI master in slave out (MISO), USI data output (DO), or pin change interrupt (PCINT6).
- PA7 (PCINT7/ADC7/MOSI/DI/SDA): This pin can be used as an analog input (ADC7), SPI master out slave in (MOSI), USI data input (DI), I2C data (SDA), or pin change interrupt (PCINT7).
Programming the Attiny84
To program the Attiny84, you need an AVR programmer, such as the AVR ISP (In-System Programmer) or the Arduino ISP. Here are the steps to program the Attiny84 using the Arduino ISP:
- Hardware Setup:
- Connect the Arduino board to your computer via USB.
-
Connect the Attiny84 to the Arduino board according to the following connections:
- VCC (Attiny84) to 5V (Arduino)
- GND (Attiny84) to GND (Arduino)
- PB0 (Attiny84) to Pin 10 (Arduino)
- PB1 (Attiny84) to Pin 11 (Arduino)
- PB2 (Attiny84) to Pin 12 (Arduino)
- PB3 (Attiny84) to Pin 13 (Arduino)
-
Configure Arduino as ISP:
- Open the Arduino IDE.
- Go to File > Examples > ArduinoISP.
-
Upload the ArduinoISP sketch to your Arduino board.
-
Install Attiny Support in Arduino IDE:
- Go to File > Preferences.
- In the “Additional Boards Manager URLs” field, enter the following URL:
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
- Click “OK” to save the preferences.
- Go to Tools > Board > Boards Manager.
-
Search for “attiny” and install the “ATTinyCore by Spence Konde” package.
-
Configure Board Settings:
- Go to Tools > Board and select “ATtiny24/44/84”.
-
Set the following options:
- Processor: “ATtiny84”
- Clock: “Internal 1 MHz”
- Programmer: “Arduino as ISP”
-
Write and Upload Code:
- Write your Arduino sketch for the Attiny84.
- Click the “Upload” button to compile and upload the code to the Attiny84.
Example Code
Here’s a simple example code that blinks an LED connected to PB0 of the Attiny84:
void setup() {
pinMode(0, OUTPUT); // Set PB0 as an output
}
void loop() {
digitalWrite(0, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second
digitalWrite(0, LOW); // Turn the LED off
delay(1000); // Wait for 1 second
}
This code sets PB0 as an output pin and alternately turns the LED on and off with a delay of 1 second.
Frequently Asked Questions (FAQ)
- What is the difference between Attiny84 and Attiny85?
-
The main difference between Attiny84 and Attiny85 is the number of I/O pins and memory size. Attiny84 has 12 I/O pins and 8KB of flash memory, while Attiny85 has 6 I/O pins and 8KB of flash memory.
-
Can I use the Attiny84 with a higher clock frequency?
-
Yes, the Attiny84 can operate at a maximum frequency of 20MHz. However, you need to ensure that the power supply voltage is sufficient for the desired clock frequency.
-
How do I set the fuse bits for the Attiny84?
-
Fuse bits are used to configure various settings of the Attiny84, such as clock source, brown-out detection, and more. You can set the fuse bits using an AVR programmer and the appropriate software, such as AVRdude.
-
Can I use the Attiny84 for PWM (Pulse Width Modulation)?
-
Yes, the Attiny84 has two timer/counters that can be used for PWM generation. You can use the OC0A, OC0B, or OC1A pins for PWM output.
-
What is the maximum analog input voltage for the Attiny84?
- The maximum analog input voltage for the Attiny84 is VCC, which is the power supply voltage of the microcontroller. If VCC is 5V, the maximum analog input voltage is also 5V.
Conclusion
The Attiny84 is a versatile and powerful microcontroller that offers a range of features and capabilities. By understanding its pin configuration and programming steps, you can effectively utilize the Attiny84 in your embedded projects. With its small size, low power consumption, and rich set of peripherals, the Attiny84 is well-suited for applications such as sensor monitoring, control systems, and IoT devices.
Remember to refer to the official Attiny84 Datasheet for more detailed information on its specifications, electrical characteristics, and register descriptions. Happy programming with the Attiny84!
No responses yet