Atmel AT32UC3
Home - Developer - Contact us

 

Up

Introduction

Literature

Chapter 1: Start

Chapter 2: Clocks

Chapter 3: Port

Chapter 4: Interrupt

Chapter 5: Timer

Chapter 6: Real Time

Chapter 7: Serial Link

 

Lecture Material

Application_3
Application_3a

Chapter 3

The way that the LED-action is programmed in Chapter 1 and Chapter 2 is for sure not elegant - the programming of the ports can be improved and using a loop for a delay time of the order of 100ms is very unpractical. The AT32UC3A3 series of controllers have advanced controlling possibilities and timers that we will use in this chapter together with interrupt routines to streamline the LED-runner program.

Ports: Output

The registers in the AT32UC3A3 controllers are 32bit wide; the AT32UC3A3256 has 110 pins which can be used for General Purpose IO (GPIO) or most of them for special functions. The mapping is thus not straight forward, the ports PA, PB, PC and PX have different sizes and thus are not helpful in mapping the pins to registers. Instead a direct mapping of pins to 32bit ports is used: there are 4 ports and given a certain pin number NP, the 32bit-port number NR is found by NR = NP/32 and the bit-position of the pin within a port by NB = NP % 32 .

Each 32bit-port has an extensive set of 45 32-bit registers (see the AT32UC3A3 datasheet p.387/388), in which individual bits (mapped to pins) can be read or written, be set or cleared or toggled, etc. For the programming you can use the extensive support available via ASF or you can can limit yourself to just what you need and right your own small handling routines. We will use here the latter approach.

On the STK600 board, we select port STK-PD (added STK for clarity) as ouput to the LEDs. This corresponds to PA24 (GPIO 24) to PA31 (Gon the AT32UC3A3256-device.

For STK-PD the 32bit-port number is:

	NR = 0 ,
and the bit positions for STK-PD are:
	NB = 24 .. 31 .

We will now initialize the GPIO-registers for our purpose. The LEDPORTMASK

In the program Application_3 the GPIO-register initialization is done in the routine gpio.c which is called from init.c during the board initialization. This simplifies the main-routine: the initialization is transferred to where it belongs, to the device specific initialization routines. The activation of the LEDs (to let them 'run') is left for the moment as it was before. For further information see the section Programs below.

Ports: Input

Till now we have only used the I/O-ports for output, we will now use the STK600 switches for input in polled mode. We select the STK600-port PC (STK-PC) as input for the STK600 switches. STK-PC corresponds to PA16 (GPIO 16) to PA23 (GPIO 23) on the controller. To make our life a bit more difficult - both STK-ports STK-PC and STK-PD are in the same 32-bit port on the controller.

For STK-PC the 32bit-port number is:

	NR = 0 ,
and the bit positions for STK-PC are:
	NB = 16 .. 23 ,

We have now to add the initialization the GPIO input-registers.

The program Application_3a adds switch-action to Application_3. Each time before switching LEDs the status of the switches is checked and the appropriate action is taken. Remeber: the switches are active low.

Programs

Application_3 keeps the logic for the 'running' LEDs in the main program, but transfers the initialization to the routines clock.c and gpio.c. These routines are called from init.c, the general board initialization routine. To setup Application_3, create a new project with the name 'Application_3' and overload the new main routine main.c and the new initialization routine init.c in your program. Also copy the directory 'support' with its contents to the 'src'-directory. Set the compiler optimization to 'None' to make the delay loop work. Load the program to the STK600 board. The LEDs should immeditely start running.

Application_3a is an extension of Application_3: it adds action activated by the STK600 switches, such as different 'run'-speeds and patterns. In the main loop in main.c we add 'polling' for the switches and set the speed of 'running' and the display mode. The meaning of the switches is:

Button 0Default speed
Button 1Default speed * 2
Button 2Default speed * 4
Button 3Default speed * 8
Button 4Default direction
Button 5Inverse direction
Button 6Restart
Button 7Stop

Start a new STK600UC3A3-project. Replace main.c with main.c in the 'Application_3a' package. Also replace the initialization routine init.c in the 'STK600'-directory. As before, create a directory 'support' in the 'src'-directory using Atmel Studio and fill the directory with the 'support'-files in the package. Remember to set the Optimization to 'none', compile the project and load it to the STK600 board. Check the operation of the switches. By the way, debouncing of the switches is not necessary the way this program is written.

info@tsseshop.com