Stairs.  Entry group.  Materials.  Doors.  Locks.  Design

Stairs. Entry group. Materials. Doors. Locks. Design

» Attiny2313 microcontroller. Description. ATTiny2313 - cheap and available Block diagram of attiny2313

Attiny2313 microcontroller. Description. ATTiny2313 - cheap and available Block diagram of attiny2313

AVR RISC architecture:

RISC (Reduced Instruction Set Computer). This architecture has a large set of instructions, most of which are executed in 1 machine cycle. It follows that compared to previous microcontrollers based on CISC architecture (for example, MCS51), RISC microcontrollers are 12 times faster.

Or if we take a certain level of performance as a basis, then to fulfill this condition, microcontrollers based on RISC (Attiny2313) require 12 times less generator clock frequency, which leads to a significant reduction in power consumption. In this regard, it becomes possible to design various devices on the Attiny2313 using battery power.

Operational Storage Device (RAM) and non-volatile memory of data and programs:

  • 2 KB of self-programmable Flash program memory that can provide 10,000 write/erase repeats.
  • 128 Bytes of EEPROM writeable data memory that can provide 100,000 write/erase repeats.
  • 128 Bytes SRAM memory (read-only RAM).
  • It is possible to use the function to protect program code and EEPROM data.

Peripheral properties:

  1. Microcontroller Attiny2313 equipped with an eight-bit timer-counter with a separately installed prescaler with a maximum coefficient of 256.
  2. There is also a sixteen-bit timer-counter with a separate prescaler, capture and comparison circuit. The timer-counter can be clocked either from an external signal source or from an internal one.
  3. Two channels. There is an operating mode of fast PWM modulation and PWM with phase correction.
  4. Internal analog comparator.
  5. Watchdog timer (programmable) with internal oscillator.
  6. Serial Universal Interface (USI).

Special technical indicators of Attiny2313:


  • Idle— Idle mode. In this case, only the central processor stops working. Idle does not affect the operation of the SPI, analog comparator, A/D converter, counter timer, watchdog, or interrupt system. In fact, all that happens is that the synchronization of the CPU core and flash memory stops. The Attiny2313 microcontroller returns to normal operation from Idle mode by an external or internal interrupt.
  • Power-down— The most economical mode, in which the Attiny2313 microcontroller is actually switched off from power consumption. In this state, the clock generator stops and all peripherals are turned off. Only the interrupt processing module from an external source remains active. When an interrupt is detected, the Attiny2313 microcontroller exits Power-down and returns to normal operation.
  • Standby– the microcontroller switches to this power consumption standby mode using the SLEE command. This is similar to shutting down, the only difference being that the clock continues to run.

Input-output ports of the Attiny2313 microcontroller:

The microcontroller is equipped with 18 I/O pins, which can be programmed based on the needs that arise when designing a specific device. The output buffers of these ports can withstand a relatively high load.

  • Port A (PA2 - PA0) – 3 bits. Bidirectional I/O port with programmable pull-up resistors.
  • Port B (PB7 - PB0) – 8 bits. Bidirectional I/O port with programmable pull-up resistors.
  • Port D (PD6 - PD0) – 7 bits. Bidirectional I/O port with programmable pull-up resistors.

Supply voltage range:

The microcontroller operates successfully with a supply voltage from 1.8 to 5.5 volts. Current consumption depends on the operating mode of the controller:

Active mode:

  • 20 µA at a clock frequency of 32 kHz and a supply voltage of 1.8 volts.
  • 300 µA at a clock frequency of 1 MHz and a supply voltage of 1.8 volts.

Power Saving Mode:

  • 0.5 µA at a supply voltage of 1.8 volts.

(3.6 Mb, downloaded: 5,958)

So, we have an ATtiny2313 microcontroller, an LPT port (an iron port is required, no USB-2-LPT works), several wires (no more than 10 cm long) and, of course, a soldering iron. It is better to have a DB - 25M (male) connector; it will be much more convenient to connect the microcontroller with it, but you can do without it. Solder the wires to pins 1, 10, 17, 18, 19, 20 of your microcontroller. You will get something like this, as in the photo:

Then, if there is a DB-25M connector, then solder the wires to it in accordance with the table shown below. And if it’s missing, then just plug the wires into the connector on the computer.

Here they did it without a connector (only the mothers were at hand), and this is what came out of it:

Here the LPT port was brought to the table using a 1.5 m long cable. The cable must be shielded, otherwise there will be interference and interference and then nothing will work. The diagram of this microcontroller programming device looks like this:

It’s better, of course, to make a “correct” programmer, since it will be simpler and the port will be more intact. In this case, STK200/300 was used. Then you need the PonyProg2000 program. After the program starts, it will “neigh” just like a real pony :). To prevent this sound from straining your ears in the future, you need to check the “Disable sound” box in the window that appears. Click OK. A window will pop up indicating that the program needs to be calibrated. Computers are different, both slow and fast. Click OK. Another window will pop up, it says that you need to configure the interface (which programmer and where it is connected). So, now go to the menu: Setup -> Calibration. In the window that appears:

Click "YES". A couple of seconds will pass and the program will say “Calibration OK”. Then go to the menu: Setup -> Interface Setup. In the window that appears, configure as shown in the figure.

Now go to the menu: Command -> Program Options. In the window that appears, configure as shown in the figure.

Now you're ready for programming! So, the steps of action:

  1. Select "AVR micro" from the list
  2. From another list you need to select “ATtiny2313”
  3. Now download the firmware file (File -> Open Device File), select the desired file, for example “rm-1_full.hex”.
  4. Click the “Launch program cycle” button. When programming is finished the program will say “Program successful”
  5. And finally, you need to program the so-called Fuses. To do this, click the “Security and Configuration Bits” button. In the window that appears, click “Read”, then check the boxes and click “Write”.

    ATTENTION! If you don't know what a particular configuration bit means, then don't touch it. Now our ATtiny2313 controller is ready for work!

    This is all. All the best.

How to assemble a simple circuit, how to connect a programmer to an ATtiny2313 microcontroller, how to write a simple program in C and how to flash an ATtiny2313 microcontroller with our program, you will find all this in this article.

First of all, we need a programmer, there are many types of programmers, which programmer should we choose?
There are ordinary programmers in which you need to insert a microcontroller, flash it, remove the microcontroller and then insert it into our board to see the result, and this sequence will have to be done hundreds of times at first, this option, in my opinion, is not convenient.
Our microcontroller ATtiny2313 Supports ISP (In-System Programming) function via SPI port, this in-circuit programming use case ISP in my opinion the most convenient and fastest, because... There is no need to remove the microcontroller from our board after each firmware update; you can program the microcontroller hundreds of times and immediately, without disconnecting the programmer from the computer and the board, see the result after flashing the microcontroller; the process of debugging the software of an amateur radio device is noticeably simplified and the time spent on this is reduced.
You can make an in-circuit ISP programmer yourself; there are many simple circuits on the Internet on how to do this via an LPT or COM port, for example a programmer PonyProg You can find diagrams on the Internet on how to make it.

This article will discuss working with an in-circuit ISP programmer for microcontrollers AVR (PX-400) it works via COM port.
If you do not have a COM port on your computer, you will also need an adapter from a USB port to a COM port, there are also many varieties of such adapters, I recommend the adapter that I worked with: UCON-232S USB to Serial port converter board
Photo of the programmer PX-400, adapter UCON-232S USB , Datasheet ATTiny2313

Let's look at all the details of this scheme in more detail:
(Just in case, I bought all the parts, programmer, adapter (from USB to COM port) at chipdip.ru)

1 - PBD-20 board socket 2.54mm 2x10 straight- I did this for convenience, to make it easier to check signals from the microcontroller pins; this point could not be done.
2 - SCS-20 DIP panel 20 pins- we solder the panel to the board so that it is possible to replace the microcontroller in the board if necessary,
ATtiny2313-20PU, DIP20, MCU, 5V, 1K-Flash, 12MHz- We insert the microcontroller into the DIP panel.
3 - Quartz crystal 4.000 MHz (truncated) HC-49S- Quartz crystal 4 MHz
4 - Ceramic capacitor K10-17B imp. 22pF NPO,5%,0805- Two 22pF ceramic capacitors
5 - 78M05 (+5V, 0.5A) TO220- A 5V voltage stabilizer supplies the microcontroller with stabilized power of no more than +5V, in this case I got 4.4V, which is enough.
6 - NP-116 power plug 1.3x3.4x9.5mm MP-331 (7-0026c)- The power plug was soldered to an old mobile phone charger DC 5.7V/800mA
7 - DS-213 power socket on board- where is the power supply for the NP-116 plug, for easy power connection
8 - IDC-10MS (BH-10), straight plug- Plug for connecting an in-circuit ISP programmer
9 - Constant resistor 0.25W 150 Ohm- Three 150 Ohm resistors on the MISO, SCK, MOSI pins
10 - Constant resistor 0.25W 47 Ohm- One 47 Ohm resistor per RESET pin
11 - Tact button h=5mm, TC-0103 (TS-A2PS-130)- RESET button, after pressing the button the program in the microcontroller starts from the beginning, the button could have been omitted.
12 - Green LED d=3mm, 2.5V, 2mA - Performs the function of an indicator, this item could not be done.
13 - Constant resistor 0.25W 110 Ohm- A resistor for the LED so that there is 2V on the LED, this step can be omitted
14 - Two wires connected to the LED, to check signals from the microcontroller pins, this step could not be done
15 - Dip-RM printed breadboard 100x100mm

Points 3 and 4 Work as a single unit, like an external clock generator, these points can be omitted if you do not place high demands on the accuracy and stability of the internal RC Oscillator, the internal RC Oscillator has an error of about 10% and the accuracy may be affected by change temperature.

So you have downloaded and installed Atmel Studio:
Let's launch Atmel Studio and write a simple program in C language blinking an LED:
Click: New project... \ AVR GCC \ C \ C Executable Project
Specify the folder where to save the project and the project name, for example Test1, and click OK.
From the list, select our ATtiny2313 microcontroller and click OK.
We erase everything that appears in the window and paste our program code below:

#define F_CPU 4000000L //Specify the frequency of our external quartz 4 MHz
#include
#include
int main(void)
{
//Set all PORTB pins as outputs
DDRB=0xFF;//Register of the direction of information transfer (1-output, 0-input)
while(1)
{
//Data register PORTB (used to output information)
PORTB=0b00000001;//We supply 1 to port 12 of MK PB0 - turn on the LED
PORTB=0b00000000;//Apply 0 to port 12 of MK PB0 - turn off the LED
_delay_ms(1000);//Delay 1 sec.
}
}

Go to the menu Build\Configuration manager\Active solution configuration\
Choose Release, press Close
We did this so that we could have a folder in the project Release, which I will talk about below.

Click F7, ready, our application has compiled!
To flash the ATtiny2313 microcontroller firmware, we need only one file with the extension HEX
It is located in our project folder: ...
Please note the file Test1.hex just take it from the folder Release !
Do not confuse, because folder Debug there is also a file Test1.hex, but this file still contains debugging information and because of this you will not be able to flash with this file because. it is usually large and will not fit in the memory of the MK.

We found the .hex file, now we need a program to flash the ATtiny2313 microcontroller, there are many such programs, but we will use the program: Avr-Osp II
Download:

We connect the programmer to our circuit, and be sure to supply power to the circuit!

Launch the program Avr-Osp II, specify the path to the file in the FLASH section... \Test1\Test1\Release\Test1.hex, check the boxes in the program and press the button Program that's it, microcontroller ATtiny2313 is flashed!

What is the advantage of in-circuit ISP programmers? Now, without disconnecting the wires from our circuit, you can make changes in the program, and, as described above, flash the microcontroller and immediately see the result.

Please leave questions and comments on our forum

A simple experiment with connecting a button to an AVR microcontroller is described, and a simple C program for processing button presses is analyzed. Let's look at the features of connecting a button to the MK ports, as well as methods for reading button states in the C language.

Previous articles discussed experiments with LEDs that were connected to microcontroller ports configured for Output.

In this article, we will connect a button to the microcontroller, the contacts of which close when pressed, and open when released (closed button).

Schematic diagram of the experiment

In order to be able to at least somehow observe and control something using a button, we will connect two more LEDs to the microcontroller. The diagram is very simple, here it is:

Rice. 1. Schematic diagram of the experiment with the ATtiny2313 microcontroller and button.

As you can see, two LEDs are connected to two ports PB0 and PB1 through limiting resistors, and a button is connected to port PD2 and it also has a limiting resistor. To connect the programmer to the MK, the Conn 1 (AVR-ISP) connector is used, and to connect the circuit to a separate +5V power source, two contacts are used - P1 and P2.

Rice. 2. An experiment diagram with a microcontroller and a button assembled on a solderless breadboard.

It is important to note that for safe use of a port with a button, a resistor with a resistance of 1 KOhm is connected in series with it (you can also connect it to another resistance of 600 Ohms - 2 KOhms). Accept this as a rule of good manners when working with pins, which will protect the MK port from failure in the event of an erroneous high-level supply to the pin and when the button is closed.

Structure of I/O ports in AVR microcontrollers

The microcontroller pins are universal GPIO (General Purpose Input Output), you can connect both actuators (indicators, power switches) and various digital sensors (buttons, switches) to them.

Several pins in the MK can be connected to an ADC/DAC (Analog-to-Digital-Converter and vice versa), with their help you can analyze and generate analog signals. Conventional GPIOs cannot work with analog signals; they can only have 0 (0V) or 1 (+5V) at their input/output.

Each GPIO pin inside the microcontroller is connected to several blocks and electronic components that are useful to know about:

  • Between the port pin and each of the power rails (GND and VCC) connected via diode. They are used to “dampen” short-term interference, voltage surges relative to the pin and each of the power rails;
  • There is also a capacitor between the pin and GND. I don’t know exactly why it is needed, perhaps for protection against interference, to prevent contact bounce when using buttons and switches connected to a pin, or for something else;
  • Connected to each pin an electronic key with a resistor is a pull-up of the pin to the voltage of the power source (Pull-UP). This electronic key is turned on by software and serves to set the default high logical level 1 (+5V) when working with a pin in input mode (Input);
  • Between the pin and each of the power buses (GND and VCC) two more electronic switches (without resistors) are included; they are needed to set a high (+5V) or low (0V) logical level on the pin when the pin is operating in Output mode.

For software control and configuration of each of the ports, three special registers are used, for example for port “B”:

  • DDRB - register (8 bits) for setting the operating modes of pins - input or output. This is done by setting the corresponding bits in the register;
  • PORTB is a register for controlling the state of the port pins in output mode - high or low level. Also used in input mode, used to enable pull-up resistors and set the default input level high;
  • PINB is a register that contains the logical states of the pins on a port, used to read the values ​​of ports that are configured in input mode.

You can learn more about the design of ports for a specific microcontroller model from its datasheet, in the “I/O-Ports” section; there may also be examples of code in C and Assembly for working with ports.

RESET pin as I/O port

It is useful to know that the “RESET” pin of the microcircuit (in our diagram it is pin number 1), which is intended for resetting the execution of the microcontroller program (reboot), can also be used to connect buttons, LEDs and other input/output devices, that is, it can be turned into a regular GPIO.

This can be useful if the microcircuit does not have enough pins for your design. For example, when assembling some device on an ATtiny13 chip (8 pins, 2 pcs for power, 5 pcs for I/O ports, 1 pc for RESET), you found that one pin was missing for the LED. There may be several options to solve the problem:

  1. Reprogramming the RESET pin for an I/O port;
  2. Connecting an LED to one of the adjacent already used pins, using some histrosts in the circuit design and taking into account the possibility of its general use;
  3. Using another MK that has more pins, for example ATtiny2313.

Which of these options is simpler and cheaper in terms of finances/time - judge according to your own case.

To turn the "RESET" pin into an I/O port, you will have to change a special fuse - RSTDISBL (Reset Disable). But before you do this, you need to remember that after this operation, reprogramming the microcontroller will only be possible using a high-voltage programmer (12V); a regular USB ISP or another programmer powered by 5V will no longer be able to do its job.

C program

So, we have one button and two LEDs that are connected to the microcontroller, what can we do with them? - and we’ll do this (algorithm):

  1. After turning on the power, the LEDs will flash alternately and with a delay of 300 milliseconds;
  2. When you press and hold the button, only the blue LED will light;
  3. After releasing the button, the blue LED will flash 3 times with a delay of 500 milliseconds, after which the LEDs will flash alternately again with a delay of 300 milliseconds.

An example of the implementation of such an algorithm in C language under AVR is given below. Let's create a new file for our program and open it for editing:

Nano /tmp/avr-switch-test.c

Let's put the following code in the body of the file:

/* Experiment with a button on ATtiny2313 * https://site */ #define F_CPU 1000000UL // Core frequency = 1 MHz #include #include // -- Macros for controlling LEDs -- #define LED_BLUE_ON PORTB |= (1<< PB0) // Засвечиваем синий диод #define LED_BLUE_OFF PORTB &= ~(1 << PB0) // Гасим синий диод #define LED_RED_ON PORTB |= (1 << PB1) // Засвечиваем красный диод #define LED_RED_OFF PORTB &= ~(1 << PB1) // Гасим красный диод // Основная программа void main(void) { DDRD |= (0 << PD2); // Пин 6 - на вход PORTD |= (1 << PD2); // Включаем подтягивающий (Pull-UP) резистор для пина 6 DDRB |= (1 << PB0); // Пин 12 - на вывод DDRB |= (1 << PB1); // пин 13 - на вывод // -- Бесконечный цикл -- while(1) { _delay_ms(300); // Задержка 300 мс LED_BLUE_ON; // Включаем синий диод LED_RED_OFF; // Гасим красный диод _delay_ms(300); LED_RED_ON; // Включаем красный диод LED_BLUE_OFF; // Гасим синий диод if(!(PIND & (1 << PD2))) { // Проверяем нажата ли кнопка _delay_ms(50); // Задержка 50 мс (дребезг контактов) LED_RED_OFF; LED_BLUE_ON; while(!(PIND & (1 << PD2))); // Ждем пока кнопка не будет отпущена _delay_ms(500); // Дальше мигаем синим диодом LED_BLUE_OFF; _delay_ms(500); LED_BLUE_ON; _delay_ms(500); LED_BLUE_OFF; _delay_ms(500); LED_BLUE_ON; _delay_ms(500); LED_BLUE_OFF; _delay_ms(200); } // Конец блока работы с кнопкой } // Конец блока с вечным циклом }

First of all we ask constant F_CPU, which will indicate to the compiler the operating frequency of the microcontroller core; this is necessary for some subroutines and functions to work correctly. In our example, we use the time delay function - "_delay_ms" from the "util/delay.h" library, which calculates the time spent on idle cycles, based on the value in the F_CPU constant.

You can view the code of the "delay" library for organizing a time delay and which uses the F_CPU constant in GNU Linux using any text editor, for example, you can run the following command:

Nano /usr/lib/avr/include/util/delay.h

The factory set frequency of the internal RC oscillator in the ATtiny2313 microcontroller is 8000000Hz (8MHz), the frequency division fuse is also set by default - CKDIV8 (Clock Divide by 8), so the actual operating frequency of the crystal = 8000000Hz / 8 = 1000000Hz = 1MHz.

You can see what fuses are installed in the microcontroller using avrdude or a graphical shell for it called AVR8 Burn-O-Mat.

Further in the program, macros are defined to control the state of the ports to which the LEDs are connected: LED_BLUE_ON, LED_BLUE_OFF, LED_RED_ON, LED_RED_OFF. By calling a similar macro anywhere in the program, we can very easily turn on or turn off each of the LEDs, without having to repeat its code, which in turn will simplify the program and make it more visual.

In the main program "void main(void)" we start with the port configuration:

  • DDRD |= (0<< PD2) - установка разряда PD2 регистра DDRD на ввод, к нему подключена кнопка (пин 6);
  • PORTD |= (1<< PD2) - включение подтягивающего резистора для пина к которому привязан разряд PD2 регистра PORTD (пин 6);
  • DDRB |= (1<< PB0) - установка разряда PB0 в регистре DDRB на вывод, к нему подключен СИНИЙ светодиод (пин 12);
  • DDRB |= (1<< PB1) - установка разряда PB1 в регистре DDRB на вывод, к нему подключен КРАСНЫЙ светодиод (пин 13).

Next, using macros, we turn off the red LED and turn on the blue one. Now, using another eternal loop, but with a condition, we will wait until the button is released: "while(!(PIND & (1<< PD2)));".

When the button is released, a high level will appear on pin 6 (this will be done by the internal pull-up resistor that we turned on earlier), and logical 1 will be set in the PD2 bit of the PIND register.

After this, the blue LED flashes three times (on-off) with a delay of 0.5 seconds and the main eternal cycle starts working in a new way - two LEDs will light up alternately.

A very simple program, but nevertheless, it is a good example and grounds for further experiments.

Setting up Geany for ATtiny2313

In previous publications I conducted experiments with the ATMega8 microcontroller, but here I use a less “stuffed” MK - ATTiny2313.

To compile the program and flash it into the MK, you need to slightly reconfigure the commands for assembly in the Geany integrated programming environment.

Go to the Build menu - Set Build Commands. In the compilation command (C commands), you need to change the model of the chip used: "-mmcu=attiny2313". In the command to flash the MK, you need to change the chip type for avrdude: "-p t2313".

Rice. 3. Reconfiguring Geany to work with the ATTiny2313 microcontroller.

All commands are given for GNU Linux OS; if you have Windows, you may have to enter the full paths to the binary files “avr-gcc.exe”, “avr-objcopy.exe”, “avrdude.exe”.

I discussed in more detail how to configure Geany in GNU Linux in one of the previous articles in the series.

Compilation and firmware of the program in MK

Compiling, assembling and flashing the program can be done by clicking three buttons in turn in the Geany environment: “Compile”, “Build” and “Run”. Also, all these operations can be performed from the console, here are the commands for these actions (perform sequentially):

Avr-gcc -mmcu=attiny2313 -Os /tmp/avr-switch-test.c -o /tmp/avr-switch-test.o avr-objcopy -j .text -j .data -O ihex /tmp/avr- switch-test.o /tmp/avr-switch-test.hex avrdude -c usbasp -p t2313 -P usb -U flash:w:/tmp/avr-switch-test.hex

All commands are almost completely (with the exception of file name substitutions) identical to those that we corrected in the Geany settings.

Conclusion

Despite the simplicity of the experiment, I also tried to highlight some very important technical aspects of working with ports; the knowledge and experience provided will be useful in further study and work with ATMEL microcontrollers.

Atmel AVR microcontrollers have been deservedly popular among radio amateurs for several years now. A special feature of these MKs is that you can write “firmware” into them in both parallel and serial modes.

Restoring the ATtiny13 Fuse bit configuration

In amateur radio practice, the most widely used are serial (SPI - Serial Peripheral Interface) programmers, which have a number of advantages: their circuits are usually simpler than those of parallel programmers (in extreme cases, you can even get by with five conductors and two resistors); there are many options for both the programmers themselves and control programs for various operating systems; To connect the programmer, you can choose almost any computer port - there are schemes for both LPT and COM, as well as USB programmers. In addition, such a programmer allows you to “flash” the MK without unsoldering it from the device (ISP - In System Programmable).

However, the SPI programming mode is still stripped down; and some full parallel programming capabilities are not available in it. The most common problem with sequential programming is the inability to perform any actions with the MK, if certain fuse cells of this MK have been changed relative to the default values ​​- in this case, the chip “goes on strike” and does not communicate with the computer: it can no longer be used neither read nor “flashed” by a serial programmer. And it seems to be out of order, while the PonyProg program, for example, produces the following error message: “Device missing or unknown device (-24), although in the final circuit this MK can work quite normally.

The reason for this “uncommunicativeness” may be, for example, setting the RSTDISBL bit to zero (and a zero in the fuse bits of an AVR means that this bit is programmed) - which leads to the external reset input being turned off and turning it into a regular I/O line; and without an external reset, the MK will not be able to enter the SPI programming mode, and will be inaccessible to the PC. Another reason why the MCU becomes “invisible” to the SPI programmer is the lack of clocking: the fuse bits that control the clock generator (CKSEL0-3) can be set in such a way that the MCU will turn off the internal clock circuits and require an external oscillator - clock source; and without clocking, SPI programming is impossible.

Moreover, incorrectly “wired” fuse-bytes can be the result not only of inattention or ignorance - hardware failures during “flashing” are also quite likely, especially if they are “sewn” through one of the variations on the theme of “five wires” - therefore, from “fallen-in No one is safe from being in a coma with MKs lying on the shelf and waiting for a miraculous healing (and if you believe the Internet, then almost every second AVR lover has gone through this - and not necessarily a beginner).

If such a problem does occur, and the MK stops establishing communication with the computer, then it will no longer be possible to correct incorrectly set fuse bytes using a serial programmer. However, it is not at all necessary to make or purchase a new parallel programmer (or, especially, a debugging kit) just to “cure” a couple of “comatose” MKs, especially if the old SPI programmer is quite satisfactory - it is more convenient for this use a simple device, the diagram of which is given on the website

The device is designed to “treat” the ATtiny2313 MK, but can be converted for any other AVR model - both Tiny and Meda - for which a well-commented “source code” of the firmware is attached, which makes it possible to rewrite it in relation to the MK for which An ambulance is needed at this moment. The essence of the operation of such a device is to put the “patient” into parallel programming mode and emulate on its lines those signals of the “real” programmer that are responsible for changing the state of fuse cells; and then write the default values ​​of fuse cells into this MK.

This device sets factory values ​​for all fuse bytes: high, low and additional; and in addition, it also erases the “patient’s” memory of programs and data - as a result of which it acquires the state of a “clean” microcircuit. Similar devices have already been described in amateur radio literature and on the Internet (under the names Fuse Doctor, AVR Doctor, AVR Reanimator, AVR Aibolit, etc.), but this one has several features that make working with it a little more pleasant. Firstly, in all the designs known to the author, the “doctor” and “patient” were connected to each other, practically “foot to foot” (with the exception of some terminals that, according to the diagram, for the “doctor” and “patient” should not be connected ).

That is, lines РВ0-РВ7 - to lines РВ0-РВ7, line PD6 - to line PD6, etc. - Which, in the case of assembling the circuit in a printed manner, significantly complicated the installation - many jumpers were required, or double-sided wiring (although some the authors proposed simply installing microcircuits on top of each other, bending the non-connected terminals to the side and soldering resistors/conductors on them; but the reliability of the contact with such a “microcontroller Kama Sutra” is called into question; and what does bending and bending the terminals of microcircuits lead to, we all we know very well). Here the microcircuits are arranged “side by side”, “jack”, which makes the layout of the printed circuit board very simple.

In the author's version, which is shown in Fig. 2, it largely repeats the circuit diagram and contains only three small jumpers. Board size - 60x60 mm. Secondly, some devices required two voltages: 5 V to power the MK, and 12 V to the “patient” reset line to enter programming mode. This circuit requires only one voltage, which can vary over a fairly wide range - the main thing is that it is at least 12 V. Thirdly, most of the devices described do not allow “hot” replacement of “patients” in case it is necessary to “cure” several MKs in a row - after each “flashing” they need to turn off the power, replace the “sick” one, then turn on the power again, etc. This device sets all outputs to log.

O after each “flashing”, which allows you to “treat” the microcircuits with a “conveyor” - connect the power, install the “patient”, press the “start” button, look at the result of the “treatment” on HL1, remove it, insert a new “patient”, press I looked at HL1, removed it, inserted it, etc. And all this without turning off the power (at least open a “tent” at the radio market!). Well, fourthly, often in such devices there is no verification of the recorded fuse bits and indication of the result of the “treatment” (of the “successful/unsuccessful” type).

In this design, verification is provided, and the HL1 LED, which can have three states, is used to indicate its results:

  1. Lights up continuously - the “patient” programming has been completed
    successful, read fuse bytes match those written;
    the device is waiting for the next “patient”;
  2. Blinking at a frequency of 2Hz - error in
    programming the “patient”:
    read fuse bytes do not match those written; "patient" has not entered programming mode, is not installed or is faulty (in
    the program provides a check for the presence of a “patient” - a working AVR sets logic 1 on the BSV/RDY line (pin 3 for ATtiny2313) when entering parallel programming mode); the device is waiting for the next
    "patient";
  3. OFF - programming and verification process is in progress. Programming a healthy “patient” takes less than a second, and this LED state should not be noticeable under normal conditions. If the LED is in the off state for a relatively long time, then, most likely, the “flashing” process has gone into a cycle due to the fact that the faulty “patient” is stuck in recording mode and does not set the BSY/RDY readiness signal expected by the “doctor”.

As already mentioned, the device is quite universal and can be used to “treat” almost any MK of the AVR series. In this case, it is not at all necessary to make a separate copy of the device for various microcontrollers that differ in the number and location of pins - it is enough to simply add, as necessary, adapters for the pinout of the next “sick” one, and rewrite the control program accordingly. The adapter is a DIP-20 socket, which is inserted with its “legs” into the “patient” panel on the device board. From above, to such a socket (to the contacts for the microcircuit pins), conductors are soldered (or simply inserted) in those places where the power and control lines approach the “patient” on the board.

The other ends of these conductors are soldered to the terminals of the second socket - under the MK that requires “treatment” - in accordance with the location of its control lines, which can be specified in the proprietary datasheet. It turns out to be a kind of connector, the plug (just a DIP-20 socket) of which is inserted into the DIP-20 socket for the “patient” on the board, and a new “patient” is inserted into its socket (another socket). As for the program, it may require correction, because... Different models of AVR MCUs often require different actions both to enter programming mode and to change fuse bytes. In addition, the fuse bytes themselves (including their number) are different for different MK models - more detailed information can be obtained in [L. 1,2,3], or in company documentation.

And to make it easier to understand the original program, I provided it with detailed comments. As a “doctor”, this device uses the same ATtiny2313 microcontroller as the “patient” - it is also installed on the socket so that after restoring all the “sick” microcircuits, it can be removed and used in other projects. To work in this device, all fuse-bits of the “doctor” must be the same as those installed in it by default (from the factory); the only thing is that for more stable operation (especially with an unstable supply voltage), in the “doctor” you can enable the BOD system by setting it to a level of 2.7 V (by setting the BODLEVEL1 fuse bit to zero).

The “doctor” does not require external quartz; it operates from a built-in RC oscillator. The DA1 (78L05) chip can be replaced with the domestic analogue KR1157EN502, or the more powerful 7805 - but it is much more expensive, and its power is not required for this circuit. Transistor VT1 here operates in key mode, and can be of any NPN structure - for example, KT315, 2SC1815, 2SC9014, 2SC1749S, etc.; but for some models you will have to change the board layout. The safety diode VD1 can be anything, with a current of at least 150 mA. its task is to protect the circuit from accidental power reversal. All resistors in the circuit are small-sized, 0.125 W - their values ​​may differ from those indicated within a fairly wide range. LED HL1 - any indicator.

And in conclusion, I would like to talk about an interesting feature of the behavior of some copies of the ATtiny2313 MK when they are SPI-programmed using the PonyProg2000 program (perhaps other MK models behave the same way, including with other programs - but the author has not yet had a chance to experiment with anything other than the ATtiny2313-PonyProg2000 combination). The essence of the problem is this: sometimes, when trying to read or write a microcontroller, the PonyProg program displays the error message “Device missing or unknown device (-24)” - and this despite the fact that no fuse bits in this microcontroller have been changed - moreover , the microcircuit may even be new, never “flashed” yet! “Treatment” using the device described above does not give any results - when you try to read/write again, the error message appears again.

The MK seems to be out of order, and for no reason at all. But if you click the “Ignore” button in this message, thereby forcing “Pony” to ignore the lack of response from MK. and still try to read/write the microcircuit, then this MK will be read or “flashed” normally. After such a forced “firmware”, most “pretending to be dead” MKs will work quite normally, and without any failures (except for the message described above when trying to establish a connection with the PC)!

Apparently, the point here is that some instances of the MK do not generate the correct confirmation in response to the programmer’s request, as a result of which PonyProg concludes that they are faulty; At the same time, these MKs perceive the remaining programmer commands normally and execute them correctly. It is quite possible that this is a feature (or rather, a “disease”) of the AVR MK (it’s not just that PonyProg included such a button - “Ignore”) - the author of this article had three out of ten MKs behave this way, and more often it started this is not immediately, but after several “firmwares”.

Or maybe the static tension on human hands is to blame. But, be that as it may, in critical designs (such as ignition devices, automatic heating, watering, alarm systems, etc.) it is still not advisable to use such “trust-breaking” MKs. But in toys, Christmas tree garlands, doorbells and other auxiliary devices (like the one described above ©) they will work quite well for many years - and without any problems.