Tag Archives: AVR

Some people just know Java very well and in order to program microcontrollers it would be best choice. But microcontrollers don’t have java Virtual Machine (VM) running in them. So there is a difficulty which has to be removed. Dmitry decided to change things a bit and programmed uJ – Java VM for microcontrollers. Its written purely in C so can be used for most microcontrollers including AVR, PIC and ARM. Lots of things are already done and many are in to do list. But results are speaking for themselves.

Biggest constrains here are RAM limits, so few workarounds are implemented in order to work correctly like not coppying classes to RAM, custom stack control and other. JVM is modular so for smaller microcontrollers some features can be turned off in order to fit and leave more space for user programs. You write java programs as you would normally write for PC of course have in mind that MCU has very limited resources. Then boobloader loads bytecode from SD card and execute from Flash leaving RAM free for data. As seen on video, execution speed is really acceptable.

Once your program is written and compiled, next concern is flashing and running on real device. Any programmer adapter dos this job quickly. But what if you don’t have adapter or you are lost in the island with attiny13 in your hands… then you can program chip manually. With some knowledge and patience you can do this with couple buttons.

As you may know avr microcontrollers are programmed through SPI interface. It consists of four wires – reset, MOSI, MISO and SCK. So all we need is to control these signals manually. Manually keying it is possible to program chip bit by bit. SPI programming speed isn’t limited towards slow. With buttons connected to these wires bits can be clocked in. As example a successful blinking LED program was programmed in to Attiny13 that way. It took 425 button clicks to do that. Here is a translated version of post.

Earlier I’ve made a mistake by referring this tutorial to older AVR family microcontrollers like Atmega8/16/32/64/128. But AVR is being changed constantly with various new tweaks and updates like enhanced pin control or different register names. Since now tutorial will be based on Atmega328 microcontroller which is popular in Arduino boards. So you’ll be able to test all code examples on Arduino as it can serve as general purpose AVR test board with no problem.

Understanding Interrupts

Probably you won’t be able to find a microcontroller without interrupt capability. These are essential attributes of any modern microcontroller or processor. They may seem confusing and tricky at first glance, but during the time you will find out that normal MCU operation is impossible without interrupts.

Interrupts can be easily compared to real life events. Look around – all your activities are full of them. For instance you are reading this tutorial and find it interesting so you are all in it. But suddenly you cell phone rings. What you do? You remember last stroke you’ve red and answer the phone. Once phone conversation is over you get back to your reading as nothing happened. Well this is only one example of interrupt to give some visual clue what interrupts are. Continue reading

You can be encouraged to use various types of AVR development tools. Most of them cost money to get full functionality and support. Most common commercial packages are: CodeVisionAVR, Imagecraft ICCV, IAR Workbench. All they are great tools out of box with fast support that you have to pay for. Of course you can give a try with their limited versions to se capabilities. As we mentioned before we are going to use free tools that great enough comparing to commercial.

WinAVR or AVR-GCC tools

WinAVR is a toolset for C programming the AVR microcontrollers. It is actually a bunch of small programs that make development as easy as possible. Main tools here are avr-gcc compiler, avrdude programmer, avr-gdb debugger and even more. These actually are command line tools so you need to integrate them in to some integrated development environment (IDE). There can be any IDE supporting external tools like Eclipse and of course AVRStudio that we will be using. Besides, WinAVR comes with great program writing tool – Programmers Notepad. Actually with WinAVR you can write, compile, upload to chip and even debug your firmware either in emulator or via hardware debugger. As we are only going to use compiler only with different IDE we won’t be going into more details. Ah, probably you will find some rumors that WinAVR-20100110 is the last release if this great tool. Eric Weddington (maintainer) who is also a Product Manager at Atmel is probably going to shift this product to official ATMEL release. This won’t affect following tutorial as it still will be based on same avr-gcc compiler. So install, use it and don’t worry. Continue reading