ATtiny85
The ATtiny85 is an Atmel 8-bit AVR microcontroller. The ATtiny falls under the tinyAVR series of AVR controllers and is more limited in terms of available memory, IO pins, and peripheral sets when compared to the megaAVR series microcontrollers found in many Arduinos. However, the ATtiny trades these limitations for lower power consumption and smaller form factor.
Getting started
Connecting the ATtiny for ISP
In-system programming (ISP) is used for programming the ATtiny. This is also sometimes referred to as ICSP (In-circuit serial programming).
The ATtiny85 in the DIP/SOIC/SOP package has 8 pins. The pinouts are shown on the right. To program the ATtiny, we will be using ISP via pins 5, 6, and 7 (outlined in orange in the diagram). Any ISP programmer will do, but we will be using an Arudino running the ArduinoISP sketch which can be found from the examples menu.
Once the ArduinoISP sketch is programmed on the Arduino, connect the ATtiny to the Arduino based on the table below.
| Arduino Pin | Function | Connect to ATtiny85 Pin |
|---|---|---|
| 10 | Reset | 1 |
| 11 | MOSI | 5 |
| 12 | MISO | 6 |
| 13 | SCK | 7 |
Connect ground and power to the ATtiny via the Arudino. You may use either 5 or 3.3 volts. A 10uF capacitor should also be connected between ground and the Arudino reset pin to prevent the Arduino from resetting during the ISP programming. At the end, it should look something like the following:
Programming the ATtiny with AVRDUDE
AVRDude (AVR Downloader/UploaDEr) is a utility that can program AVR microcontrollers using ISP. Once the appropriate connections are made, we can use avrdude to read/write to the microcontroller.
avrdude takes some required options:
-c programmer-id- specify the programmer you are using. When using the Arduino as the ISP programmer, you may use theavrisporarduino(which appears to be aliases forstk500) as the programmer.-p part-number- the board you are targeting-P port- the device or port that is connected to the ISP programmer. On Windows, it is probably someCOM#port. On Linux, it's likely to be/dev/ttyUSB#.-B bit-clock- Used to adjust the SPI speed. Default is 10, for 100KHz. KHz = 1000/(1.5+B).
Some useful commands to be aware of:
| Task | Command |
|---|---|
| Read fuse settings | avrdude -c avrisp -b 19200 -p attiny85 -P /dev/ttyUSB0 -U lfuse:r:-:i
|
| Change fuse settings | avrdude -c avrisp -b 19200 -p attiny85 -P /dev/ttyUSB0 -U lfuse:w:0xXX:m -U hfuse:w:0xXX:m -U efuse:w:0xXX:m
Be careful when setting the fuses for an external clock. You may need to adjust the SPI speed in your programmer or via the -B option in avrdude. |
| Write flash | avrdude -c avrisp -b 19200 -p attiny85 -P /dev/ttyUSB0 -U flash:w:firmware.hex
|
Other notes
ATtiny configuration fuses
There are some configuration settings that can be set on the ATtiny. These settings can change the behavior of the microcontroller such as changing its clock speed or using an external clock source.
Despite its name, these fuses are really just flash/EEPROM values used as configuration parameters. You may change these values at a later time and are values don't actually blow any fuses.
There is a fuse calculator at https://www.engbedded.com/fusecalc/ for a wide array of AVR microcontrollers.
Implementing the crazy clock with an ATtiny85
Random notes:
- All 6 port B pins can be used as IO lines to the internal 8 bit bus (high bits, lower 2 bits aren't connected?)
- System clock can be selected with CKSEL. It can use the internal 8MHz ocillator (with some options which sets it to 16 or 8mhz) An external clock is given with XTAL1 and XTAL2.
- Regardless of the oscillator, CLKPS sets the prescaler
- Setting the wrong clock setting can be problematic to recover from. You would likely need to inject a clock signal.
Fuses
Other resources
- https://www.electroschematics.com/attiny85-pwm-primer-tutorial-using-arduino/
- https://circuitdigest.com/microcontroller-projects/attiny85-ic-programming-through-usb-using-digispark-bootloader
Comparisons
The distinction between the other ATtiny microprocessors are:
| ATTiny25 | ATTiny45 | ATTiny85 | |
|---|---|---|---|
| Programmable Flash Memory (10k write/erase) | 2K | 4K | 8K |
| EEPROM (100k write/erase) | 128 bytes | 256 bytes | 512 bytes |
| SRAM | 128 bytes | 256 bytes | 512 bytes |
| Program Counter bits wide | 10 | 11 | 12 |