AVR Coding Part 1: Microchip Studio

Atmel AVR microcontrollers are semiconductors that accept programs written in the C, C++, and assembly languages, and others.

In an earlier project, I covered how to program AVRs using Atmel Studio 7 and the free AVR-GCC compiler.  Since then, Microchip has rebranded this software as Microchip Studio with the release Microchip Studio 7.0.2539.  Today’s project will show you have to get this program installed, and what you can expect to see during your first run.

Notice of Non-Affiliation and Disclaimer: As of the publication date, we are not affiliated with, associated with, authorized with, endorsed by, compensated by, or in any way officially connected with Microchip Technology Inc., or Microsoft, or their owners, subsidiaries or affiliates. The names Microchip Technology Inc. and Microsoft, as well as related names, marks, emblems, and images are trademarks of their respective owners.

External Links: Links to external web pages have been provided as a convenience and for informational purposes only. Unboxing Tomorrow and Voxidyne Media bear no responsibility for the accuracy, legality or content of the external site or for that of subsequent links. Contact the external site for answers to questions regarding its content.

Objectives

To program an AVR microcontroller, at a minimum you will need:

  • A personal computer
  • The AVR microcontroller
  • A programmer/debugger tool and its included cables

…plus a few passive components and a fixed voltage supply.  For early guidance on where to start: visit the previous tutorial: AVR Coding Part 0: Procurement.

Before you Start

The reprogramming step at the end of this guide will erase any data already stored on your AVR chip.  This includes any bootloader(s) such as the one used in Arduinos.  So be mindful of using AVRs from existing products unless you accept this loss of data.  AVRs generally ship from the factory as a blank slate, and this is the type of AVR this tutorial will address.

Electrostatic Discharge

Like any other digital device, AVRs are susceptible to electrostatic discharge (ESD), which is a topic I’ve covered in Anti-Static: Why All the Fuss.  For now, just know you can avoid many ESD-induced problems by working at an anti-static workstation.

Step 1: Download Microchip Studio

To download the latest version of Microchip Studio, or to get the older, archived version; visit the official Microchip website (https://microchip.com).

Enter “Microchip studio” in the search field, or navigate to “Tools and Software” –> “Microchip Studio for AVR and SAM Devices.”

Follow Microchip’s instructions that best match your operating system.  In this example, I have downloaded Microchip Studio for AVR and SAM Devices 7.0.2542 Web Installer.

Figure 1: The Official Microchip Studio Site

As with anything you download off the internet, scan everything with your favorite anti-malware program.  If it looks safe, run the installation program, and then stick around for the configuration dialogs.

Step 2: Configuring the Installation

Microchip Studio is an integrated development environment (IDE).  Its installer will not only give you the code editor, but also the hardware drivers, compilers, and software frameworks for the AVR series. 

Review the End User License Agreement

When you run the installer, you will see the end-user license agreement, the default installation directory, and the option to send anonymous information.  Review your options and proceed if you approve.  The current version includes links to the GNU Compiler Collection (GCC), the AVR-libc library, and other open-source resources used by the AVR GCC compiler.

Select Architecture

Next, you need to select the architectures of interest.  At a minimum, you will need “AVR” enabled, but I will install all three.

Atmel Software Framework

Optionally, you can install the Atmel Software Framework (ASF).  The ASF includes hardware abstraction tools that can be handy in advanced projects.

Figure 2: Installation Configuration Screens

Release Notes

Optionally, you can view the release notes.

Step 3: System Validation

The installer will test whether anything might interfere with the installation.  This includes Windows Updates in progress, conflicts with other software, etc.  You will need to see all checkmarks (☑) before you can go further.

Figure 3: Installation Configuration (Continued)

Before long, your installation will begin.

There is a good chance the system will automatically offer to install the Microsoft Visual Studio Isolated Shell.  You should stay near your computer in case you are asked to verify.

Step 4: Locate the Tool in Device Manager

If the installation succeeded, now would be a good time to open Windows Device Manager to make certain your tool is listed.

Plug in your programming tool via the USB cable if you haven’t already.  After a short delay, it should appear under a new category “Microchip Tools.”

Figure 4: Example View of Windows Device Manager

Step 5: Launch Microchip Studio

With the tool still plugged in, launch the Microchip Studio application.

Step 6: (Recommended) Check Notifications and Updates

The Microchip Studio IDE will occasionally check for routine updates.  Notifications will appear as a yellow flag in the top-right corner, which you should check periodically.

  • Click the notifications flag
  • Follow the on-screen instructions for any relevant updates.
  • Be prepared to restart the Microchip Studio application or unplug and re-plug the tool, if the update requires it.
Figure 5: Microchip Studio Notifications Location

Step 7: Is Your Device Listed?

Back at the start page, you can test your programming tool by navigating to Tools –> Device Programming.  You can also access this quickly by clicking the icon with the lightning bolt over a computer chip.

The Device Programming screen should list your tool (and a simulator) if it is reachable.

Figure 6: All Tools Plugged into the USB Should Appear in the Highlighted Area

Some brand-new “MPLAB” and “PIC” branded tools such as the Microchip SNAP may require a firmware upgrade before Microchip Studio will recognize them.  If this is the case, your tool will be visible in Device Manager, but not in Microchip Studio.  To remedy this, you will need to install Microchip MPLAB X first, and then:

  • Create an empty project for any PIC device (such as PIC16F18446)
  • Select your tool
  • In the dashboard view: click the two rotating arrows (🔄) and follow any additional instructions.

…and then return to this step.

 “Atmel” or “AVR” branded tools such as the AVR ISP Mk II and the ATMEL-ICE usually work with Microchip Studio right out of the box.

Step 8: Test Device Programming

If you have collected the hardware shown in AVR Coding Part 0: Procurement, then you should have just enough components to push an empty executable program from Microchip Studio to the device.

To test: navigate to Microchip Studios File –> New –> New Project.

In the New Project Wizard, select the GCC C Executable Project option.  For now, the default project name and location are acceptable, so click OK.  Then answer any remaining questions about your AVR part number as completely as possible.

The IDE should automatically generate a near-empty project containing only a main() function and a while() loop.  Immediately build the empty program by pressing F7, or navigate to “Build –> Build Solution” to do the same.

Figure 7: The IDE After Building the Blank Solution

Step 9: Upload

Finally, return to the Tools –> Device Programming window seen previously.

The tool, device, interface, device signature, and target voltage should all be readable.

Common Problems

  • Errors while uploading to a visible tool will strongly suggests the ISP interface is mis-wired.  This can easily happen due to accidentally mirroring or rotating the ISP connection from its correct pinout; or by mis-numbering the connector in your circuit board layout.
  • Target voltage = 0 will cancel any programming attempts by the AVR ISP MkII and Atmel ICE programmers.  Many tools will not supply your AVR with electrical power (at least not by default).  Your circuit must have its own power source active unless you have one of the few tools that provides power to the VCC pin.

Additional Resources

Linux users wishing to program AVRs also have a free, open-source software option: avrdude.  While avrdude is outside the scope of this short article, you can check for a avrdude writeup.

The Microchip Studio and MPLAB X products are actively maintained do change from time to time.  In the event of any inconsistencies between this tutorial and the official guides, you should refer to the official instructions.

References

[1]B. Mayes, “Programming AVR Microcontrollers with Atmel Studio 7,” Voxidyne Media, 9 July 2020. [Online]. Available: https://unboxing-tomorrow.com/programming-atmel-microcontrollers-with-atmel-studio-7/. [Accessed 7 Aug 2021].
[2]Microchip Technology Inc., “Microchip Studio for AVR® and SAM Devices,” Microchip Technology Inc., [Online]. Available: https://www.microchip.com/en-us/development-tools-tools-and-software/microchip-studio-for-avr-and-sam-devices. [Accessed 7 Aug 2021].
[3]B. R. Mayes, “AVR Coding Part 0: Procurement,” Voxidyne Media, 15 Aug 2021. [Online]. Available: https://unboxing-tomorrow.com/avr-coding-part-0-procurement/. [Accessed 6 Sep. 2021].
[4]B. Mayes, “Anti-Static: Why All the Fuss?,” Voxidyne Media, 4 Sept. 2020. [Online]. Available: https://unboxing-tomorrow.com/anti-static-why-all-the-fuss/. [Accessed 15 Aug 2021].

Important Notice: This article and its contents (the “Information”) belong to Unboxing-tomorrow.com and Voxidyne Media LLC. No license is granted for the use of it other than for information purposes. No license of any intellectual property rights is granted.  The Information is subject to change without notice. The Information supplied is believed to be accurate, but Voxidyne Media LLC assumes no responsibility for its accuracy or completeness, any error in or omission from it or for any use made of it.  Liability for loss or damage resulting from any reliance on the Information or use of it (including liability resulting from negligence or where Voxidyne Media LLC was aware of the possibility of such loss or damage arising) is excluded.