starting AVR development

9,460

Circuit Image

This tutorial examines the essential tools required for developing C programs on 8-bit AVR microcontrollers. It demonstrates how to write a C program and upload it to an AVR microcontroller, specifically utilizing an ATtiny2313 microcontroller breadboard circuit as a test setup. The microcontroller will be powered by a 5V supply sourced from a PC power supply. An LED and a resistor will be necessary for circuit assembly. Single-strand, single-core wire will be utilized to connect the microcontroller to the AVR programmer. After downloading Atmel Studio, the installation is initiated by executing the downloaded file. Once the software is installed, the AVRISP mkII device should be connected to an available USB port on the PC, which will automatically install the necessary drivers. The circuit is to be constructed on a breadboard, and connections from the ISP header in the circuit diagram are made to link the AVRISP mkII to the ATtiny2313 using single-strand wire. The project should be saved under the name "attiny2313_blink," ensuring that this name is entered in the Name field, not the Solution name field. In the subsequent dialog box, the target device must be selected by using the Device Family drop-down menu to choose tinyAVR, 8-bit, followed by selecting ATtiny2313 from the table. The program code provided includes the necessary headers and a simple blinking LED routine. The power supply to the ATtiny2313 must be activated (5V supply), and within the Device Programming dialog box, the Read button should be clicked under Target Voltage to display the voltage reading. Additionally, clicking the Read button under Device Signature will show the device signature.

The development process for programming the ATtiny2313 microcontroller begins with the assembly of the breadboard circuit. The circuit should include the ATtiny2313 microcontroller, an LED connected to one of its GPIO pins (PB0 in this case), and a current-limiting resistor to protect the LED from excessive current. The microcontroller requires a stable 5V power supply, which can be obtained from a standard PC power supply unit (PSU). The connection of the AVRISP mkII programmer to the microcontroller is crucial for programming and debugging. The ISP header on the ATtiny2313 will have specific pins for MISO, MOSI, SCK, RESET, VCC, and GND, which must be connected to the corresponding pins on the AVRISP mkII.

After ensuring that the hardware connections are correct, the Atmel Studio software must be configured. The user should create a new project and select the appropriate device family and model. The provided C code initializes the data direction register to set PB0 as an output. The main loop toggles the state of PB0, causing the connected LED to blink on and off. The Delay function introduces a simple timing mechanism by creating a loop that counts down, effectively pausing the execution of the program.

Before programming the microcontroller, it is essential to verify the correct voltage and device signature in the Device Programming dialog. This ensures that the programmer is communicating correctly with the target device. Once these checks are complete, the compiled program can be uploaded to the ATtiny2313, allowing the LED to blink according to the programmed logic. Proper documentation of each step and careful attention to connections will facilitate a successful development experience with the ATtiny2313 microcontroller.This tutorial looks at the tools needed to start development (C programming) on 8-bit AVR microcontrollers and shows how to write a C program and load it to an AVR microcontroller. An ATtiny2313 microcontroller breadboard circuit will be used as the test circuit. This microcontroller will be powered by 5V the 5V from a PC power supply will be used. An LED and resistor will be required to build the circuit. Single strand, single core wire will be needed to connect the microcontroller to the AVR programmer. After downloading Atmel Studio, install it by running the downloaded executable file. After software installation, plug the AVRISP mkII device into a spare USB port on the PC. The drivers for the AVRISP mkII should automatically be installed. Build the circuit on a breadboard and use the connections from the ISP header in the circuit diagram to connect the AVRISP mkII to the ATtiny2313 using single strand wire. 3. Choose the location to save the project to and choose a project name. The project for this tutorial will be named attiny2313_blink. Be sure to fill this name into the Name field and not the Solution name field. 4. In the next dialog box that pops up, select the device. Use the Device Family drop-down box to select tinyAVR, 8-bit and then select the device in the table below ATtiny2313.

#include void Delay(void); int main(void) { DDRB |= 1 << PB0; while(1) { PORTB &= ~(1 << PB0); Delay(); PORTB |= 1 << PB0; Delay(); } } void Delay(void) { volatile unsigned int del = 16000; while(del-); } Switch the power to the target on (the 5V supply to the ATtiny2313). In the Device Programming dialog box, click the Read button under Target Voltage a voltage should be read and displayed. Click the Read button under Device signature a device signature should be read and displayed. 🔗 External reference