Same as Arduino but tiny. ATtiny13 MCU only has 64bytes of usable RAM and 1kByte flash program storage. Only 6 IOs from PORTB.
Sketches have to be brief. We will use an Artou DevBoard with LEDs on B3 and B4.
MicroCore is a board package for Arduino to program for the ATtiny13 MCU. Follow the instructions at the MicroCore github page. Open menu File->Preferences and add Additional Boards Manager URL:
https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json
Go to Tools->Boards and install MicroCore. Installation will take a moment while MicroCore adds a few files to the Arduino program.
These files are called cores. They map out a processor and features so that Arduino can compile code for new and different MCUs. Example: PB3 is a reserved keyword label for the fourth IO pin on the chip, PB4 is the fifth IO pin.
Select ATtiny13Menu Tools->Board->MicroCore->ATtiny13.
Look at bottom of Arduino IDE screen to make sure it is setup to program for the ATtiny13 MCU.
Enter this code for the sketch. It will toggle pins PB3 and PB4 on the ATtiny module. Our board has LEDs connected to these leads.
void setup() { pinMode(PB3,OUTPUT); pinMode(PB4,OUTPUT);}
void loop() { digitalWrite(PB3,HIGH);digitalWrite(PB4,LOW); delay(500);
digitalWrite(PB3,HIGH);digitalWrite(PB4,HIGH);delay(500);
digitalWrite(PB3,LOW); digitalWrite(PB4,HIGH);delay(500);
digitalWrite(PB3,LOW); digitalWrite(PB4,LOW); delay(500); }
Click the check mark and make sure that the sketch compiles okay. The ATtiny has only 1kB of flash memory to store programs, our blinky program uses 7% of that.
Arduino IDE menu Tools->Programmer select USBasp
Menu Sketch->Upload Using Programmer.
Since the IC integrated circuit package is a complete SOC system on a chip all we need is to add power and the ATtiny will start up and run the program it has in flash. We did not need to add any buffer circuits for this to work.
We can connect to a programmer with short, loose wires but we may need to use a slower baudrate speed parameter like -b 1200.
Notice that the LED on PB5 does not fully light. It is in pinMode(input) and a resistor pulls the lead up to 5v without enough current to light the LED.
PB5 is a reset input that we need to for device programming. We can recover the pin and use it as a normal IO but we may lose our ability to change the program.
Burn Bootloader?Let us talk about it. I don't think we need to.
- A bootloader program takes up flash in a device that is limited
- A bootloader program is only needed for Arduino IDE
- Without a bootloader the device can still talk through a serial or USB interface
- Many MCUs will only ever be programmed once
Set Arduino IDE for ATTiny13 device, select programmer, yes for bootloader menu Tools-> Burn Bootloader. Look in the verbose output for two lines of white text.
This is the command to burn fuse circuits in the device.
This shows a hex file uploaded to the chip. It is the compiled boot program.
Comments