Controlling AVR I/O ports with AVR-GCC

Controlling pins is one of the first things to learn when learning microcontrollers. It seems that each microcontroller type has its port logic. So before using them, it is essential to understand every detail so you can effectively use them in projects. Let’s see how ports are organized in AVR and how to successfully control them. Inside AVR port If you try to look into any AVR datasheet, you will find port drawing which may seem a bit complex at the start. But for a simple start, let’s look at simplified port pin schematic. x designates port (A,B,S,D,…); n designates pin number (0..7) As you can see, each port consists of three registers DDRx PORTx, and PINx (for instance, DDRA, PORTA, and PINA). When looking into this simple logic, we can see several variants of operation. To enable output to the pin, we need to write logic ‘1’ to DDx.n pin. This will enable buffer to let bit through from PORTx register. If the PORTx.n bit is ‘1’, then it can source a pin with VCC voltage and up to…

Continue reading

Setting up AVR development platform

You can be encouraged to use various types of AVR development tools. Most of them cost money to get full functionality and support. All they are great tools out of the box with fast support that you have to pay. Of course, you can give it a try with their limited versions to see capabilities. As we mentioned before, we will use free tools that are great enough compared to commercials. UPDATE! Here are the currently supported software options for AVR microcontroller development: WinAVR or AVR-GCC tools WinAVR is a toolset for C programming the AVR microcontrollers. It is a bunch of small programs that make development as comfortable as possible. The main tools are avr-gcc compiler, avrdude programmer, avr-gdb debugger, and more. These are command-line tools, so you need to integrate them into 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…

Continue reading

Choosing AVR programmer

There are many AVR programmers to choose from. The simplest ones are bitbang programmers. These are straightforward programmers that can be built with as few components as few resistors (or no resistors at all). These can be COM, LPT, or USB-to-TTL converter based. DIY Bitband programmers Example of LPT port programmer These are probably the simplest to build, as there is no need to convert any signals from the port. Buffer chip is used only for safety reasons to protect computer port. Even simpler programmer cable can be found here.

Continue reading

Things needed before you learn AVR

There are several things you need to do before learning AVR. First of all, you need an AVR chip. You better choose megaAVR series, so you don’t need to worry about the lack of peripherals when required. Atmega8, Atmega16, or further mega’s will do correctly. Probably chose in DIP package as it will easily fit in breadboard for fast prototyping.  Development boards are great to work with, primarily designed for learning and prototyping.  Any Arduino board can be used with no problem, as it has all the necessary means to serve as a general-purpose dev board. Anyway, I leave this up you for a while. The next thing is the programmer. This is where you can get a headache. Really! In a few words, a programmer is a cable/device used to upload firmware (compiled program) to chip. Programmers can be connected to the computer via various ports, including parallel (LPT), serial (COM), and USB. Or there can be no programmer at all if the chip has a bootloader set up. But this will be discussed later. These were two hardware…

Continue reading

AVR at a glance

Any AVR microcontroller is an 8-bit computer in a chip designed and manufactured by ATMEL Corporation. It has some RAM and ROM (Flash) as well. There is also an EEPROM memory. Including AVR core CPU, all these are more than enough to say that it is a small computer where you can execute programs stored in Flash memory, run them while operating data in SRAM, and store some constant values in EEPROM. Compared to the actual computer that sits on your table, you can say that AVR core is a CPU like AMD or Pentium. Flash memory would be your hard drive where programs are stored; RAM is RAM nothing to add there. EEPROM can probably be compared to some media devices like CDRW. Anyway, this is only similitude in a different scale. AVR microcontrollers aren’t limited with core CPU and memory. The main thing that makes them valuable (and any other type of microcontroller) – they are rich in peripherals inside the chip. In most cases, you will find USART, I2C, SPI, ADC, Timers/Counters, and a bunch of I/O…

Continue reading

AVR tutorial. Initial word

AVR family is one of the leading 8-bit microcontrollers in its family. There are many reasons why many hobbyists chose this one among others. I don’t say that other families like PIC are worse – no way – can you find even better solutions if needed? Let’s not get into a big fight “what’s the best.” Brilliant engineers don’t fight – they choose the one that will do the job with less effort, less cost, and probably the most familiar one. Let’s stick with AVR for a while, as it is quite a favorite type among today’s hobbyists. Who doesn’t know Arduino? It is also based on AVR MCUs. So, interest in AVR is significant, demand is big, but one thing is missing – knowledge on how to program these babies effectively. You can find tons of various libraries and tutorials on how to do simple tasks like LED blinking, USART, I2C SPI communications, and other interfacing. This is great, but when your project grows into something more significant, you are stuck because simple big while() loop in the main…

Continue reading