© EnSol AS 2018
EnSol AS
AVR-32: Atmel’s 32-Bit UC3C Microcontrollers Atmel’s AVR-32 series of microcontrollers offers a tremendous increase in power and flexibility over its AVR-8 (8-bit) controllers, but there is little information available on the net about them. Atmel does have extensive documentation with its AVR-32 framework files, but this can be a little hard to get into, and not very easy to understand what’s actually going on. Most of the examples also tend to be specific for a particular demonstration board, so it can be a bit of a leap in at the deep end developing your own application. These pages are aimed at helping making the transition. Basic connections: For ease of availability and soldering I have chosen the 32UC3C264C-U controller. To make sure you have all the connections needed for your application for these UC3 C devices Atmel does have the handy AVR32768  application note with schematic check-list. The schematic (opposite) shows the very basic connection for powering, programming and de-bugging. (With an additional 3 LEDs connected for demonstrating the port functions.) For my own testing I am using a JTAGICE MKII with AVR visual studio 6.2. I found that version 6.0 had a few bugs in it like not showing up some of the ports when debugging. Getting to grips with the ports: The first important information you need from the  data sheet is found in section 3.2.1 table 3-1 (page 11) which shows the various pin functions and allocations on the controller (an extract is shown opposite). We can see pin 42 (PC18) is linked to General- Purpous Input/Output –  GPIO number 82. Like the 8-Bit controllers the AVR-32 also have a series of different ports, with associated (32-bit) registers to allow access to them. However the various Port C, Port D.. etc are not as strictly defined. So  the correct GPIO port number is calculated by dividing the GPIO number by 32 (and rounding down): GPIO Port Number = floor (82/32) = 2 The corresponding GPIO pin number is now calculated as the remainder of the GPIO number divided by 32: GPIO Pin Number = remainder (82/32) = 18 (See page 461 of the data sheet for more information.) Now we know which pins we are dealing with we need to set them to outputs and switch them. There are several different commands available for switching the GPIO functions: (S)et – Sets a particular pin or pins to 1. (C)lear – Sets a particular pin or pins to 0. (T)oggle – Toggles / cycles a particular pin or pins 0, 1, 0, 1 etc. (And the direct command without suffix which sets all the pin values.) Firstly we need to enable the particular pins using the GP Enable Register command, in this case we use the Set  command gpers:   As the commands are typed into Atmel studio the auto-complete function will assist with finding the correct commands. The statement is interpreted as; using the AV32_GPIO functions, working on port [2], using GPIO (set) enable register, and writing a 1 to bit No. 17 (ie. 1 left shifted 17 places).   Next we need to set the pins as outputs, by enabling the pin drive function with the Ouput Driver Enable Set command: Finally we’re ready to switch the LEDs off and on. This is done using the OVR command, to set all the pins directly or using Set, Clear and Toggle options for only changing a particular pin (in a similar way to the sbi and cbi functions used with AVR-8 programming.  (See page 461 of the data sheet for more information.) So we can now put together a simple program to sequentially light the LEDs. (Note the AVR-32 does not support the _delay_ms() function of the AVR-8 so the LEDs will flash rather quickly!!
Basic connections for 32UC3C3264 microcontroller.
AVR32_GPIO.port[2].gpers=1<<17; // Activate GPIO number 81 – PC17 AVR32_GPIO.port[2].gpers=1<<18; // Activate GPIO number 82 – PC18 AVR32_GPIO.port[2].gpers=1<<19; // Activate GPIO number 83 – PC19
AVR32_GPIO.port[2].oders=1<<17; // Enable output driver GPIO number 81 AVR32_GPIO.port[2].oders=1<<18; // Enable output driver GPIO number 82 AVR32_GPIO.port[2].oders=1<<19; // Enable output driver GPIO number 83
AVR32_GPIO.port[2].ovr=1 <<17; // Drive Pin 41 GPIO number 81 high (all other pins low) AVR32_GPIO.port[2].ovc=1 <<17; // Drive Pin 41 GPIO number 81 low AVR32_GPIO.port[2].ovs=1 <<17; // Drive Pin 41 GPIO number 81 high AVR32_GPIO.port[2].ovt=1 <<17; // Toggle Pin 41 GPIO number 81 high
#include <avr32/io.h> unsigned int i; int main(void)  { AVR32_GPIO.port[2].gpers=1<<17; // Activate GPIO number 81 – PC17 AVR32_GPIO.port[2].gpers=1<<18; // Activate GPIO number 82 – PC18 AVR32_GPIO.port[2].gpers=1<<19; // Activate GPIO number 83 – PC19 AVR32_GPIO.port[2].oders=1<<17; // Enable output driver GPIO number 81 AVR32_GPIO.port[2].oders=1<<18; // Enable output driver GPIO number 82 AVR32_GPIO.port[2].oders=1<<19; // Enable output driver GPIO number 83 while (1) { AVR32_GPIO.port[2].ovr=1 <<16; //Set Pin i=0; while (i<10000) { i=i+1; } AVR32_GPIO.port[2].ovr=1 <<17; //Set Pin i=0; while (i<10000) { i=i+1; } AVR32_GPIO.port[2].ovr=1 <<18; //Set Pin i=0; while (i<10000) { i=i+1; } } }