Contacts

We connect the button to the ATtiny2313 microcontroller, a simple program. Programming attiny2313 Programming attiny2313 avr studio


Characteristics:

  • AVR RISC architecture
  • AVR - high quality and low power RISC architecture
    120 instructions, most of which are executed in one clock cycle
    32 8 bit general purpose working registers
    Fully static architecture
  • RAM and non-volatile program and data memory
    2 KB of self-programmable in the system Flash memory of the program, capable of withstanding 10,000 write / erase cycles
    128 Bytes EEPROM-programmable data memory capable of withstanding 100,000 write / erase cycles
    128 Bytes onboard SRAM (static RAM)
    Programmable protection against reading Flash program memory and EEPROM data memory
  • Peripheral characteristics
    One 8-bit Timer / Counter with Separate Prescaler
    One 16-bit Timer / Counter with separate Prescaler, Compare, Capture and Dual PWM Channels
    Built-in analog comparator
    Programmable watchdog timer with built-in generator
    USI - Universal Serial Interface
    Full duplex UART
  • Special characteristics of the microcontroller
    Built-in debugger debugWIRE
    In-system programming via SPI port
    External and internal interrupt sources
    Idle, Power-down and Standby power-down modes
    Improved power-on reset shaping circuit
    Programmable Intermittent Power Failure Detection
    Built-in calibrated generator
  • I / O ports and frame design
    18 programmable I / O lines
    20-pin PDIP, 20-pin SOIC and 32-pin MLF package
  • Supply voltage range
    1.8 to 5.5 V
  • Working frequency
    0 - 16 MHz
  • Consumption
    Active mode:
    300 μA @ 1 MHz @ 1.8 V supply
    20 μA @ 32 kHz @ 1.8 V supply
    Low consumption mode
    0.5 μA @ 1.8 V supply


General description:

The ATtiny2313 is a low power 8 bit CMOS microcontroller with AVR RISC architecture. By executing instructions in one cycle, the ATtiny2313 achieves 1 MIPS throughput at a 1 MHz master clock, allowing the designer to optimize the consumption-to-performance ratio.

The AVR core integrates a rich instruction set and 32 general purpose working registers. All 32 registers are directly connected to the arithmetic logic unit (ALU), which allows access to two independent registers with a single instruction. As a result, this architecture can provide tens of times more performance than the standard CISC architecture.

The ATtiny2313 has the following specifications: 2KB flash programmable program memory, 128 byte EEPROM data memory, 128 byte SRAM (static RAM), 18 general purpose I / O lines, 32 general purpose working registers, 1-wire interface for an embedded debugger, two flexible timer / counter with comparison circuits, internal and external interrupt sources, serial programmable USART, universal serial interface with start condition detector, programmable watchdog timer with built-in generator, and three software-initialized power-down modes. Idle halts the kernel, but the RAM, timers / counters, and interrupt system continue to function. In Power-down mode, the registers retain their value, but the generator stops, blocking all instrument functions until the next interrupt or hardware reset. In Standby mode, the master oscillator runs while the rest of the instrument is idle. This allows the microprocessor to start up very quickly while conserving power in idle mode.

The device is manufactured using Atmel's high-density non-volatile memory technology. Built-in ISP Flash allows you to reprogram the program memory in the system via the serial SPI interface or a conventional non-volatile memory programmer. By combining an 8-bit RISC core with a self-programming Flash memory in a single die, the ATtiny2313 has become a powerful microcontroller that gives a great deal of flexibility to the microprocessor system designer.

The ATtiny2313 is supported by a variety of software tools and integrated development tools such as C compilers, macro assemblers, software debuggers / simulators, in-circuit emulators, and evaluation kits.

The schematic diagram of the LPT port programmer is shown in the figure. Use a 74AC 244 or 74HC244 (K1564AP5), 74LS244 (K555AP5) or 74ALS244 (K1533AP5) chip as a bus driver.

The VD1 LED indicates the recording mode of the microcontroller,

LED VD2 - readings,

LED VD3 - power supply to the circuit.

The circuit takes the voltage required for power supply from the ISP connector, i.e. from a programmable device. This circuit is a revised circuit of the STK200 / 300 programmer (added LEDs for ease of operation), so it is compatible with all PC programmer programs working with the STK200 / 300 circuit. To work with this programmer use the program CVAVR

The programmer can be executed on a printed circuit board and placed in the LPT connector housing, as shown in the figures:




To work with the programmer, it is convenient to use an LPT port extension cable, which is easy to make yourself (for example, from a Centronix cable for a printer), the main thing is not to spare the conductors for the ground (18-25 connector feet) or buy. The cable between the programmer and the programmable microcircuit should not exceed 20-30 cm. How are ATtiny2313 microcontrollers programmed? So, we have an ATtiny2313 microcontroller, an LPT port (necessarily iron - no USB-2-LPTs work), several wires (no more than 10cm in length) and, of course, a soldering iron. It is desirable to have a DB-25M connector (dad), it will be more convenient to connect a microcontroller with it, but you can do without it. We solder the wiring to pins 1, 10, 17, 18, 19, 20 of the microcontroller. We get something like the one in the photo:


I did it without a connector (only mothers were available ...), and this is what happened:


True, my LPT port is placed on the table using a 1.5 meter cable. But at the same time, the cable must be shielded, otherwise there will be pickups, interference and nothing will work. The diagram of this microcontroller programming device is as follows:


To be completely honest, it is advisable to assemble a "correct" programmer. And then it will be easier and the port is more intact. I am using STK200 / 300. Next, we use the PonyProg2000 program. After starting the program, she will "laugh ...." like a real pony. To stop hearing this in the window that appears, check the "Disable sound" checkbox. We press "OK". A window pops up that says that you need to calibrate the program. Computers are different and slow and nimble. We press "OK". Another window pops up - this tells us that we need to configure the interface (which programmer and where is connected.). So go to the menu: Setup -> Calibration. In the window that appears:


We press "YES". A couple of seconds pass and the program says "Calibration OK". Next, go to the menu: Setup -> Interface Setup. In the window that appears, configure it as shown in the figure.


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


Everything is ready for programming! ... So, the sequence of actions:


1. Choose from the list "AVR micro"
2. From another list, select "ATtiny2313"
3. Load 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 the programming is complete, the program will say "Program successful"
5. And finally, the so-called fuses must be programmed. To do this, press the "Security and Configuration Bits" button. In the window that appears, click "Read", then check the boxes and click "Write".

ATTENTION! If you do not know what a particular configuration bit means, then leave it alone. Now we have the ATtiny2313 controller ready to work! On the forum you can download the program PonyProg2000 and the original article with additional pictures. Material for the Radiocircuit website was provided by Ansel73.

An example of how the programmer worksAVR ISP USB Lwith microcontrollerATtiny2313 A.

Introduction

AVR ISP USB L is an STK500 compatible programmer and is intended for programming (in conjunction with the AVR Studio program) all 8-bit RISC microcontrollers of the AVR series with in-circuit programming (ISP interface).

AVR ISP USB L Specifications

Compatible with AVR Studio (AVR Studio 4.12 and later);

Supports all 8-bit AVR microcontrollers with in-circuit programming (ISP interface);

Support for Flash and EEPROM programming;

Support for programming the configuration bits ( fuses) and lock bits (lockbits);

Adjustable programming speed (1.2kHz, 4.0kHz, 57.6kHz, 115.2kHz, 460.8kHz and 1.845MHz SCK frequencies);

USB bus powered, no external power supply required;

Two processor supply voltages 3.3 V and 5.0 V (selectable by a jumper);

Short-circuit protection (self-healing fuse), it is allowed to power a programmable microcontroller in a circuit that consumes no more than 50 mA.

Initial preparation for work

To get started with AVR ISP USB L follow these steps:

    Install AVR Studio.

    Install the USB driver.

    Connect AVR ISP USB L to the computer, the computer should detect and automatically

install new equipment.

    Using the device manager, determine the number of the virtual comport, which should be located in the aisles from (COM1) to (COM8). Re-number the comport if its number is higher than (COM8).

    Connect the microcontroller to the programmer (in this example it is ATtiny2313A-PU). The microcontroller is new, which has never been programmed.

Beginning of work(checking communication with the programmer)

Launch AVR Studio and press the button () on the toolbar, this button allows you to select which programmer and communication port should be connected to. Select STK500 (AVR ISP USB L in-circuit programmer is command compatible with STK500) and

virtual comport, in this example it is (COM4). Press the button ( ) :

If the programmer is not found (this virtual port does not exist, the programmer is connected to a different port, the programmer is not connected):

Attention! The programmer can only work with virtual ports from COM1 to COM8.

If the connection is successful, a window will appear:

The programmer is successfully connected, you can start programming directly.

Microcontroller programming (reading signature bytes)

After successfully connecting the programmer and the computer, check the connection with the microcontroller. The ATtiny2313A microcontroller must be connected to the programmer according to the diagram:

The presence of a quartz resonator is optional if you plan to operate from the built-in RC oscillator.

To check the connection with the ATtiny2313A microcontroller, go to the (Main) tab.

The (Main) tab contains two groups of settings:

    Device and Signature Bytes

    Programming Mode and Target Settings

Device and Signature Bytes

This group contains two buttons:

The () button that, when pressed, will completely erase the selected device. This erases the Flash and EEPROM as well as the lock bits.

The () button, when pressed, reads the bytes of the microcontroller signature.

Programming Mode and Target Settings (Programming mode and SCK signal frequency)

There is one button in this group (), when pressed, the window for selecting the frequency of the SCK signal appears.

The new ATtiny2313A microcontroller has a clock frequency of 1 MHz, therefore, the SCK frequency should be no higher than 250 kHz. The nearest suitable speed is 115.2 kHz. Of course, you can program at the SCK speed equal to 4 kHz, but then the programming process will take a long time. Select a clock frequency of 115.2 kHz and press () to record the setting. The setting is saved in the non-volatile memory of the programmer:

This group also contains a list of programming modes, make sure that “ISP mode” is selected. "PP / HVSP mode" is not supported by this programmer:

Directly to read the signature bytes, from the drop-down list, select the desired microcontroller, in our case it is ATtiny2313A:

Press the button (). If there is no communication with the microcontroller (wrong connection), the “ISP Mode Error” window will appear:

The “ISP Mode Error” window may also appear if the SCK frequency is too high.

The SCK signal frequency must be four times lower than the microcontroller clock frequency!

If the signature bytes are read successfully:

Directly bytes of the signature of the ATtiny2313A microcontroller (data from the documentation for the microcontroller):

0x000: 0x1E (Atmel Vendor Code).

0x001: 0x91 (Flash size 2KB).

0x002: 0x0A (this is an ATtiny2313 / A microcontroller if byte 0x001 is 0x91).

Communication with the microcontroller is established, we proceed to programming the configuration bits.

Microcontroller programming (writing configuration bits)

The (Fuses) tab contains the configuration bits available for the selected microcontroller type (ATtiny2313A).

Configuration bits called a special memory area (3 bytes) in AVR microcontrollers responsible for the initial (global) configuration. With these bits, we tell the microcontroller which master oscillator to work with (external / internal), divide the oscillator frequency by a factor or not, use the reset leg as a reset or as an additional I / O port, the amount of memory for the bootloader and much, much more. Each controller has its own set of configuration bits. All configuration bits are written in the microcontroller documentation. From the factory, by default, the configuration bits are set for the microcontroller to work from the internal master oscillator. You don't need to add anything to the power supply, and it works. If you need to somehow change the operation of the microcontroller, for example, make it work from an external crystal resonator, you need to change the corresponding bits.

Please note that the complete erasure of the microcontroller ( ) does not affect configuration bits.

Description of the configuration bits of the ATtiny2313A microcontroller. The new microcontroller has the following settings:

Attention! Do not turn off the SPIEN bit. Turning this bit off will disable serial programming and the microcontroller will not respond.

Attention! Do not include the RSTDISBL bit. A RESET foot is required in sequential programming mode. Turning on this bit will turn off the RESET foot and the microcontroller will not respond.

An example of config bit settings for our example:

BODLEVEL - 2.7 volts

CKDIV8 - disabled

After finishing setting the settings, press the button ().

Successful programming ends with a message (field at the bottom of the tab):

After recording the settings, the microcontroller operates from an internal 8MHz RC oscillator. RESET threshold - 2.7 volts.

Microcontroller programming (Flash and EEPROM firmware)

Before starting work, you need to download an example project in assembler (ATtiny2313A microcontroller) for AVR Studio. Link: TEST_ ATtiny2313 A_01. zip

Unpack the archive to an arbitrary folder or root directory. In this example, it is D: \ TEST_ATtiny2313A_01 \

Attention! Folder and file names must be in Latin only.

To program Flash and EEPROM memory of the microcontroller, go to the (Program) tab.

On this tab, we are interested in the following groups of settings:

Device(Device)

Flash(Program memory)

EEPROM(Non-volatile memory)

For direct programming, we specify the path to * .hex and (if necessary) to * .eep files.

Next, press the button ( ), which is in the "Flash" group, if we want to program the Flash memory of the microcontroller.

In case of successful programming of the Flash memory of the microcontroller:

Also, in case of a Flash programming error, a window appears (there is no communication with the microcontroller or the SCK frequency is too high):

To program the EEPROM, press the button ( ), which is located in the "EEPROM" group.

In case of successful programming of the EEPROM memory of the microcontroller:

In case of programming error:

Also, in case of an EEPROM programming error, a window appears (there is no communication with the microcontroller or the SCK frequency is too high):

Additionally, on the (Program) tab, there is a group of settings ( ELF Production File Format):

The .elf file can contain the contents of both FLASH and EEPROM, as well as the configuration and lock bits. This format is convenient to use in production when you need to program a large number of microcontrollers with one firmware.

To create a * .elf file you need:

    Specify the path to the * .hex file.

    Specify path to * .eep file.

    Set and program the configuration and security bits.

    Check boxes.

Successful saving of * .elf file ends with the message:

To program the microcontroller with the * .elf file, you need:

Microcontroller Programming (Write LockBits)

LockBits - designed to protect the Flash and EEPROM memory of the microcontroller from unauthorized reading. The protection bits are programmed last. To read and program the security bits, go to the (LockBits) tab. The (LockBits) tab shows which program protection modes are available for selection for a given type of microcontroller. The protection bits are read from the microcontroller and displayed:

In our case, three modes are available:

No memory lock features enabled ”- the security bits are not set.

Further programming disabled- programming of the microcontroller is prohibited, reading is allowed.

Further programming and verification disabled- programming and reading of the microcontroller is prohibited.

Once the “Further programming and verification disabled” security level is enabled, it is not possible to downgrade it by selecting the lower “Further programming disabled” security level. The only way to clear the set lock bits is to perform a full erase of the microcontroller, which also erases the Flash and EEPROM.

Additional features (reading calibration byte)

The calibration byte contains a trim value that must be written to the OSCCAL register to tune the internal RC oscillator frequency (if you plan to use it). The generator calibration byte is written to the microcontroller during production and cannot be erased or changed by the user.

    Oscillator Calibration Byte

This group contains:

To read the contents of the calibration byte, from the drop-down list, select the frequency of the RC-generator 8 MHz and press ( ).

The calibration byte value is 0x60.

The value of the calibration byte is not available directly from the program. But with the help of the programmer, it can be written to any memory cell of the microcontroller (Flash or EEPROM) and then read from the program and written to the OSCCAL register.

An example of writing a calibration byte to EEPROM at address 20 (decimal) for an 8MHz RC oscillator.

From the drop-down list, select ( ) the frequency of the RC oscillator is 8 MHz. In the text field “Address” ”enter 20. Set the radio button (). Press the button ().

A successful write of the calibration byte ends with the message:

Additional features (Automatic mode)

To program multiple microcontrollers with the same firmware, the ( Auto) offers a tool to automate the execution of a user-defined sequence of commands. The commands are listed in the order of execution. To enable the command, select the appropriate checkbox.

After pressing the () button, the following sequence of operations will be performed:

“Erase Device” - to erase the microcontroller.

“Program Flash” - program Flash memory.

“Verify Flash” - compare Flash and * .hex file.

“Program EEPROM” - program the EEPROM memory.

“Verify EEPROM” - compare EEPROM and * .eep file.

“Program Fuses” - program the configuration bits.

“Verify Fuses” - compare the configuration bits (with previously set).

"Program lock bits" - program the protection bits.

“Verify lock bits” - compare the protection bits (with previously set).

Attention! For the first programmable microcontroller, the configuration bits and the protection bits must be set.

If necessary, you can write a command execution protocol to a text file by including

checkbox (), " Recording the protocol to a file". After checking the box" Log to file"all output from commands will be written to a text file. The file is selected / created by pressing the button" Browse" ("Overview") and choosing the place where it is placed or should be created. The output will be saved to this file and later can be viewed in a text editor.

Once set, the same programming sequence will be performed each time the () button is pressed.

Additional tabs (HWSettings)

(HW Settings) tab for STK500 programmer only.

Additional tabs (HWInfo)

The (HW Info) tab displays the firmware version of the programmer.

8-bit AVR microcontroller with 2 KB programmable in the system Flash memory

Characteristics:

  • AVR RISC architecture
  • AVR - high quality and low power RISC architecture
    120 instructions, most of which are executed in one clock cycle
    32 8 bit general purpose working registers
    Fully static architecture
  • RAM and non-volatile program and data memory
    2 KB of self-programmable in the system Flash memory of the program, capable of withstanding 10,000 write / erase cycles
    128 Bytes EEPROM-programmable data memory capable of withstanding 100,000 write / erase cycles
    128 Bytes onboard SRAM (static RAM)
    Programmable protection against reading Flash program memory and EEPROM data memory
  • Peripheral characteristics
    One 8-bit Timer / Counter with Separate Prescaler
    One 16-bit Timer / Counter with separate Prescaler, Compare, Capture and Dual PWM Channels
    Built-in analog comparator
    Programmable watchdog timer with built-in generator
    USI - Universal Serial Interface
    Full duplex UART
  • Special characteristics of the microcontroller
    Built-in debugger debugWIRE
    In-system programming via SPI port
    External and internal interrupt sources
    Idle, Power-down and Standby power-down modes
    Improved power-on reset shaping circuit
    Programmable power outage detection circuit
    Built-in calibrated generator
  • I / O ports and frame design
    18 programmable I / O lines
    20-pin PDIP, 20-pin SOIC and 32-pin MLF package
  • Supply voltage range
    1.8 to 5.5 V
  • Working frequency
    0 - 16 MHz
  • Consumption
    Active mode:
    300 μA @ 1 MHz and 1.8 V supply
    20 μA @ 32 kHz @ 1.8 V supply
    Low consumption mode
    0.5 μA @ 1.8 V supply

ATtiny2313 block diagram:


General description:

The ATtiny2313 is a low power 8 bit CMOS microcontroller with AVR RISC architecture. By executing instructions in one cycle, the ATtiny2313 achieves 1 MIPS throughput at a 1 MHz master clock, allowing the designer to optimize the consumption-to-performance ratio.

The AVR core integrates a rich instruction set and 32 general purpose working registers. All 32 registers are directly connected to the arithmetic logic unit (ALU), which allows access to two independent registers with a single instruction. As a result, this architecture can provide tens of times more performance than the standard CISC architecture.

The ATtiny2313 has the following specifications: 2KB flash programmable program memory, 128 byte EEPROM data memory, 128 byte SRAM (static RAM), 18 general purpose I / O lines, 32 general purpose working registers, 1-wire interface for an embedded debugger, two flexible timer / counter with comparison circuits, internal and external interrupt sources, serial programmable USART, universal serial interface with start condition detector, programmable watchdog timer with built-in generator, and three software-initialized power-down modes. Idle halts the kernel, but the RAM, timers / counters, and interrupt system continue to function. In Power-down mode, the registers retain their value, but the generator stops, blocking all instrument functions until the next interrupt or hardware reset. In Standby mode, the master oscillator runs while the rest of the instrument is idle. This allows the microprocessor to start up very quickly while conserving power in idle mode.

The device is manufactured using Atmel's high-density non-volatile memory technology. Built-in ISP Flash allows you to reprogram the program memory in the system via the serial SPI interface or a conventional non-volatile memory programmer. By combining an 8-bit RISC core with a self-programming Flash memory in a single die, the ATtiny2313 has become a powerful microcontroller that gives a great deal of flexibility to the microprocessor system designer.



Did you like the article? Share it