Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

IMDL Software Series

University of Florida, EEL-5666


Drs. A. A. Arroyo & E. M. Schwartz
1
Atmel/AVR Studio 6
Atmel AVR Xmega Code
Getting Started with ASF,
I/O Ports & USART
A. A. Arroyo
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
2
Todays Menu
Getting Started with Atmel ASF in AVR
Studio 6 for the Epiphany DIY Board
General Purpose I/O Pins
Serial I/O
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
3
AVR Studio 6 & Atmel ASF
Creating new ASF Projects using AVR Studio 6
for the Epiphany DIY Board(s)
Step 1: Select Open New Project on the AVR Studio 6 Opening Screen
or alternatively select New>Project from the File Menu (ctrl+shift+n)
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
4
AVR Studio 6 & Atmel ASF
Step 2: Select Users Boards, User application template User Board
XMEGA A and enter a name for your project and select a directory
for your project in the New Project Window. Hit OK when ready.
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
5
AVR Studio 6 & Atmel ASF
Step 3: Select ATmega64A1 in the device selection window (Epiphany
DIY uses the ATmega64A1). Hit OK.
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
6
AVR Studio 6 & Atmel ASF
Step 6: Add path .. Toolchain Directories section. Hit OK.
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
7
AVR Studio 6 & Atmel ASF
Step 7: Add symbol F_CPU=32000000 to the Toolchain Symbols
section. Hit OK
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
8
AVR Studio 6 & Atmel ASF
Step 7: Add Compiler Optimization to Os as Shown. Hit OK
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
9
AVR Studio 6 & Atmel ASF
Step 8: Import init.c & user_board.h and [lcd.h, motor.h] which are
used by user_board.h from Tims Project.
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
10
AVR Studio 6 & Atmel ASF
Step 9: Start writing your code by modifying main.c and creating any
.c and .h files as appropriate.
#include <asf.h>
#include <avr/io.h>
#include <stdio.h>
int main(void) {
board_init(); // initialize the DIY Board
// TODO place your initialization code here
while(1) { // Main Loop
//TODO write your main loop code here
}
}
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
11
AVR Studio 6 & Atmel ASF
The first example will use PortC pins to toggle
external LEDs connected to pins PC0 & PC1
Import System Clock, Delays, and IOPORT
service & drivers from the ASF Library
In directory src/asf/common/services/ioport/xmega
the system imports ioport.h
In file ioport.h, after the macro:
#define IOPORT_CREATE_PIN(port, pin) ((IOPORT_ ## port) * 8 + (pin))
add the following macro (for convenience):
#define IOPORT_CREATE_ID(port) ((IOPORT_ ## port) + 0)
See project ASF_IOPORT
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
12
AVR Studio 6 & Atmel ASF
If you wish to use GPIO functions, add the GPIO
service from the ASF Library. The GPIO service
requires ioport.h and most of the GPIO functions
actually call the corresponding IOPORT functions
in the ASF Library
The second example uses the GPIO functions in
lieu of the IOPORT functions (these functions
have been deprecated)
See project ASF_GPIO
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
13
! !"#$ &'($)* +,*-./ 01.2 322)4$
! The first result is a nice 7-page document explaining
EXACTLY how to set up the serial USART on the
Xmega. The source code for this example is easily
found on the internet.
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
14
USART
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
15
USART
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
16
USART
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
17
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
18
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
19
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
20
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
21
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
22
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
23
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
24
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
25
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
26
! Here is the register summary for the USART. We can see
that serial communication requires the use of 7 registers
! 1 for data
! 1 for status
! 3 for control
! 2 for baud rate
USART
0 0 1 0 0 0 0 0
0 0 0 1 1 1 0 0
0 0 0 0 0 0 1 1
0 0 0 0 1 1 1 0
1 0 1 1 1 0 0 0
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
27
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
28
USART
The third example uses the USART functions in
conjunction with the IOPORT functions
See project ASF_USART
If you wish to use Tims USART functions, then
import uart.c and uart.h from Tims Software
The ISR for the USART is in uart.c and it can be
modified as needed.
See project ASF_USART
Change the include in main.c to <uart.h>
IMDL Software Series
University of Florida, EEL-5666
Drs. A. A. Arroyo & E. M. Schwartz
29
The End!

You might also like