avr xmega getting started io ports usart
TRANSCRIPT
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
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.
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.
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
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
} }
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
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
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
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
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
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>
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!