Top Banner
University of Florida, EEL 5666: IMDL © Drs. Arroyo & Schwartz IMDL Software Series University of Florida, EEL-5666 © Drs. A. A. Arroyo & E. M. Schwartz 1 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 5 for the Epiphany DIY Board • General Purpose I/O Pins • Serial I/O
15

AVR XMega Getting Started IO Ports USART

Oct 24, 2014

Download

Documents

abhijit_mote
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

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

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

Page 2: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

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)

IMDL Software Series

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

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.

Page 3: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

AVR Studio 5 & 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 5 & Atmel ASF Step 4: Open the Project Properties (alt-F7) & select Generate Hex Files

by checking the appropriate check box.

Page 4: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

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

AVR Studio 5 & Atmel ASF Step 7: Add symbol “F_CPU=32000000” to the Toolchain Symbols

section. Hit OK

Page 5: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

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 Tim’s Project.

IMDL Software Series

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

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

} }

Page 6: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

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

See project ASF_IOPORT

IMDL Software Series

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

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

Page 7: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

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

IMDL Software Series

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

USART

Page 8: AVR XMega Getting Started IO Ports USART

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

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

Page 9: AVR XMega Getting Started IO Ports USART

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

Page 10: AVR XMega Getting Started IO Ports USART

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

Page 11: AVR XMega Getting Started IO Ports USART

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

Page 12: AVR XMega Getting Started IO Ports USART

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

Page 13: AVR XMega Getting Started IO Ports USART

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

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

Page 14: AVR XMega Getting Started IO Ports USART

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

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 Tim’s USART functions, then import uart.c and uart.h from Tim’s 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>

Page 15: AVR XMega Getting Started IO Ports USART

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

IMDL Software Series

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

The End!