ATtiny13 firmware and programming with Arduino UPD 03/17/2016
Hello. There has long been a way to program small, cheap, energy-efficient and affordable ATtiny13A microcontrollers.
That's actually all that is lower, only in video format: ')
Today I will tell you how I am sewing Arduino sketches in ATtiny13A . So, first we need to download this archive here (taken and just a little done from here ), put the files at "\ Documents \ Arduino \ hardware \". You should get something like "C: \ Users \ Administrator \ Documents \ Arduino \ hardware \ attiny13 \ avr \ cores \ core13".
Restarting the Arduino IDE if it is running at the moment, this is necessary for the environment to add a new microcontroller to the list of boards.
Be sure to check if we have chosen the “location of the folder with the sketches” (you can see in the tab “File / Settings”):
There we will need to unpack the archive with the kernel for ATtiny13.
Now we’ll try to get the ArduinoISP from the Arduino IDE examples:
Then we connect ATtiny13 to Arduino, as shown in the picture:
Then you need to change the type of programmer to Arduino as ISP, as shown in the screenshot:
Now we can choose at what frequency the ATtiny13 microcontroller can operate. From the factory, ATtiny13 operates at a frequency of 1.2 MHz, that is, the microcontroller is clocked from the internal RC circuit at a frequency of 9.6 MHz and the divisor is turned on by 8, so I indicated the frequency at 1.2 MHz as default:
As you can see, the available frequencies are 1.2 MHz, 4.8 MHz and 9.6 MHz. To change the frequency, we need to click on the “Write downloader” button, which is located in the “Service” tab.
What does the medium do when you click on the “Write downloader” button?
Arduino IDE in this case simply exposes the desired microcontroller fuses . For example, I need ATtiny13 to work at a frequency of 4.8 MHz, I select the frequency I need and press the “Write bootloader” button once - that’s all. Now the microcontroller will always work at a given frequency, if it is necessary to change the frequency again - we perform the procedure described above.
At once I will say that the increase in frequency will result in an increase in the consumption of the controller, the more often the transistors in the microcontroller switch, the more it consumes. For some kind of flashing lights, I think the execution of 1.2 million instructions will be more than enough, and even at such a frequency the microcontroller consumes about 1 milliampere, here you can see the screen from the datasheet :
The minimum operating voltage at which the ATtiny13 remains operable is 1.8 V, and it is guaranteed to work, in this case, only at a frequency of 1.2 MHz.
So, to begin with, to begin with, an example of a blink, almost native to novice Arduinschik, how can it be without it?
As you have already noticed, the sketch has become noticeably lighter than for Arduino Uno. This is due to the fact that most of the Arduino functions are trimmed down, and they are a little more optimized.
So, as we just saw, only 1024 bytes are available to us. Is it enough? Well, depending on what tasks. If, for example, for some flashing lights, tweeters or indicators, I think it will be quite enough, although you can even bungle something more seriously, especially if you get acquainted with AVR-C.
Pinout of the microcontroller from the datasheet :
For example, PB4 is the same as pin 4, or simply 4. Analog inputs - everything on which ADC * writes, for example PB4 - this is ADC2, that is, in order to read the voltage, we write analogRead (A2); or just analogRead (2) ;, the hardware PWM only supports ports 0 and 1.
UPD0: added a link how to save space on a microcontroller and how to simulate an Arduino in the Proteus program: