A lightweight Arduino hardware package for ATtiny13, ATtiny13A and ATtiny13V. This core requires at least Arduino IDE v1.6, but v1.6.13 or newer is recommended.
This core is almost a complete rewrite of the at13 repository, which is again based on Smeezekitty's core13. A lot of work has been put into this fork to make it up to date with the latest requirements.
If you're into "pure" AVR programming, I'm happy to tell you that all relevant keywords are being highlighted by the IDE through a separate keywords file. Make sure to check out the example files (File > Examples > AVR C code examples).
- Why add Arduino support for these microcontrollers?
- Supported clock frequencies
- GCC flags
- BOD option
- Programmers
- Core settings
- How to install
- Getting started with MicroCore
- Pinout
- Minimal setup
- Working Arduino functions
- They're SUPER cheap (we're talking cents here!)
- They come in both DIP and SOIC packages
- They're pin compatible with the ATtiny25/45/85
- You can still fit a lot of low level code into 1024 bytes 😉
The ATtiny13 has several internal oscillators, and these are the available clock frequencies:
- 9.6 MHz internal oscillator (default)
- 4.8 MHz internal oscillator
- 1.2 MHz internal oscillator
- 600 kHz internal oscillator
- 128 kHz internal watchdog oscillator *
If you want other or higher clock frequencies, you can apply an external clock source. Note that the ATtiny13 requires an external clock signal, and is not able to drive a resonator circuit itself. You may use a quartz crystal oscillator. Supported external clock frequencies:
- 20 MHz external oscillator
- 26 MHz external oscillator
- 12 MHz external oscillator
- 8 MHz external oscillator
- 1 MHz external oscillator
Select the ATtiny13 in the boards menu, then select the clock frequency. You'll have to hit "Burn bootloader" in order to set the correct fuses. Make sure you connect an ISP programmer, and select the correct one in the "Programmers" menu.
* Make sure to use one of the "slow" programmer options when using the 128 kHz option (e.g USBtinyISP (slow)).
Compiler flags indicate what level of optimization the compiler should use. Just leave this on the default setting if you don't know what this is. If you want to learn more about compiler flags and link time optimization (LTO), head over to the GNU GCC website. Ralph Doncaster has also written a great post about LTO you should read.
Available compiler flags:
- -Os LTO enabled (default)
- -Os
- -O1 LTO enabled
- -O1
- -O3 LTO enabled
- -O3
Compiler optimization can certainly make your code smaller in size. Still, it's all about writing efficient code. Atmel have actually created an application note on how to write more efficient C code for AVR microcontrollers. This is great knowledge, so you should absolutely check it out - AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers.
Brown out detection, or BOD for short lets the microcontroller sense the input voltage and shut down if the voltage goes below the brown out setting. These are the available BOD options:
- 4.3 v
- 2.7 v
- 1.8 v
- Disabled
When the ATtiny13 is running from the internal 128 kHz oscillator, it's actually too slow to interact with the programming tool. That's why this core adds some additional programmers to the list, with the suffix (slow). These options makes the programmers run at a lower clock speed, so the microcontroller can keep up.
The externalprogrammers.txt
file is for use with the Arduino Eclipse plugin, and will not appear under the "Programmers" menu in the Arduino IDE.
Select your microcontroller in the boards menu, then select the clock frequency. You'll have to hit "Burn bootloader" in order to set the correct fuses and upload the correct bootloader.
Make sure you connect an ISP programmer, and select the correct one in the "Programmers" menu.
To make sure you're able to fit your whole project into this tiny microcontroller and still be able to use Arduino functions, I've added some core settings. By modifying the core_settings.h
file you can enable or disable core functions you need or don't need.
For instance, you save about 100 bytes of flash if you're willing to disable the millis() function.
If you know what you're doing and want full control, you can disable the safemode. For instance safemode makes sure that PWM gets turned off if a pin drives high or low, or digital pins don't exceed the number 5 (6 digital pins in total). By disabling safemode you'll gain some speed and flash space.
This installation method requires Arduino IDE version 1.6.4 or greater.
- Open the Arduino IDE.
- Open the File > Preferences menu item.
- Enter the following URL in Additional Boards Manager URLs:
https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json
- Open the Tools > Board > Boards Manager... menu item.
- Wait for the platform indexes to finish downloading.
- Scroll down until you see the MicroCore entry and click on it.
- Click Install.
- After installation is complete close the Boards Manager window.
Click on the "Clone or download" button in the upper right corner. Extract the ZIP file, and move the extracted folder to the location "~/Documents/Arduino/hardware". Create the "hardware" folder if it doesn't exist. Open Arduino IDE, and a new category in the boards menu called "MicroCore" will show up.
Ok, so you have downloaded and installed MicroCore, but how do you get the wheels spinning? Here's a quick start guide:
- Hook up your microcontroller as shown in the pinout diagram.
- Open the Tools > Board menu item, and select ATtiny13.
- Select your prefered BOD option. Read more about BOD here.
- Select your prefered clock frequency. 9.6 MHz internal oscillator is the default setting. Do not use the external oscillator option if you don't have an external clock source. Remember that a regular two pin crystal will not work on the ATtiny13.
- If you want you can change the compiler flags for further optimization. Leave this on the default setting if you don't know what compiler flags are.
- Select what kind of programmer you're using under the Programmers menu. Use one of the slow programmers if you're using the 128 kHz oscillator option, e.g USBtinyISP (slow).
- Hit Burn Bootloader to burn the fuses. The "settings" are now stored on the microcontroller!
- Now that the correct fuse settings is sat you can upload your code by using your programmer tool. Simply hit Upload, and the code will be uploaded to the microcontroller.
- If you want to do some changes; change the BOD option for instance, you'll have to hit Burn Bootloader again.
This diagram shows the pinout and the peripherals of ATtiny13. The Arduino pinout is directly mapped to the port number to minimize code footprint.
Click to enlarge:
- abs()
- analogRead()
- analogWrite()
- attachInterrupt()
- bit()
- bitClear()
- bitRead()
- bitSet()
- bitWrite()
- constrain()
- degrees()
- delay()
- delayMicroseconds() Macro wrapper for _delay_us() (inline function)
- detachInterrupt()
- digitalRead()
- digitalWrite()
- highByte()
- interrupts()
- lowByte()
- map()
- max()
- min()
- micros() Must be manually enabled in the core settings
- millis() Watchdog timer based. Will increase with steps of 16
- noInterrupts()
- noTone()
- pinMode()
- pow()
- pulseIn() micros() must be enabled in the core settings first
- radians()
- random()
- randomSeed()
- round()
- shiftIn()
- shiftOut()
- sizeof()
- stopTone
- sq()
- sqrt()
- tone()