Anda di halaman 1dari 15

IMDL Software Series

Atmel AVR Xmega Code Getting Started with ASF, I/O Ports & USART
A. A. Arroyo

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

IMDL Software Series

Today s Menu
Getting Started with Atmel ASF in AVR Studio 5 for the Epiphany DIY Board General Purpose I/O Pins Serial I/O

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

AVR Studio 5 & Atmel ASF


Creating new ASF Projects using AVR Studio 5 for the Epiphany DIY Board(s)
Step 1: Select Open New Project on the AVR Studio 5 Opening Screen or alternatively select New>Project from the File Menu (ctrl+shift+n)

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

IMDL Software Series

AVR Studio 5 & 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.

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

AVR Studio 5 & Atmel ASF


Step 3: Select ATmega64A1 in the device selection window (Epiphany DIY uses the ATmega64A1). Hit OK.

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

IMDL Software Series

AVR Studio 5 & Atmel ASF


Step 4: Open the Project Properties (alt-F7) & select Generate Hex Files by checking the appropriate check box.

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

AVR Studio 5 & Atmel ASF


Step 6: Add path .. Toolchain Directories section. Hit OK.

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

IMDL Software Series

AVR Studio 5 & Atmel ASF


Step 7: Add symbol F_CPU=32000000 to the Toolchain Symbols section. Hit OK

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

AVR Studio 5 & 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.

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

IMDL Software Series

AVR Studio 5 & 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 } }
University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

10

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

AVR Studio 5 & Atmel ASF


The first example will use GPIO pins to toggle external LEDs connected to pins PC0 & PC1 Import the IOPORT from the ASF Library In directory src/asf/xmega/drivers/ioport the system imports ioport.c and ioport.h In file ioport.h, after the macro:
#define IOPORT_CREATE_PIN(port, pin) ((PORT_##port) + (pin))

add the following macro (for convenience):


`

#define IOPORT_CREATE_ID(port) ((PORT_##port) / 8


University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

See project ASF_IOPORT


11

IMDL Software Series

AVR Studio 5 & 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
See project ASF_GPIO

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

12

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

Type xmega usart into Google

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.
13

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

IMDL Software Series

USART

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

14

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

USART

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

15

IMDL Software Series

USART

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

16

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

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

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

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

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

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

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

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

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

25

IMDL Software Series

USART

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


26

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

27

IMDL Software Series

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 uart.c and it can be modified as needed.
See project ASF_USART Change the include in main.c to <uart.h>
University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

28

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

IMDL Software Series

The End!
University of Florida, EEL-5666 Drs. A. A. Arroyo & E. M. Schwartz

29

University of Florida, EEL 5666: IMDL Drs. Arroyo & Schwartz

Anda mungkin juga menyukai