Tutorial: Getting Started with STK600 and ATMega2560
Introduction:
The objective of this tutorial is to get you familiar with development environment of STK600 and ATMega2560.
In this tutorial, we will cover the tools, concepts, and example programs required to start working with the STK600 kit. In addition, a quick how-to of utilizing USB Logic Analyzer for debugging and testing is provided (we don't want more burned servo). Hopefully you will find this tutorial helpful in getting your project going.
Hardware Summary
The STK600 starter kit is shipped with a device board with a ATmega2560 AVR microcontroller.
The STK600 starter kit contains the following components:
|
The STK600 can source power to the microcontroller through the USB cable. The power switch turns the STK600 main power on and off. The red LED is lit when power is on, and the status LED will turn green. The green LED beside the VTG jumper indicates that the target voltage is present.
STK600 Features
- 8 onboard switch button
- 8 onbaord single color LEDs
- Onboard reset button
STK600 Block Diagram
ATmega2560 microcontroller Features
- 256KB self-programming Flash Program Memory
- 8KB SRAM
- 44096 Bytes EEPROM
- 16 Channel 10-bit A/D-converter
- JTAG interface for on-chip-debug
- Up to 16 MIPS throughput at 16 MHz
- 1.8 - 5.5 Volt Operation
- Max 86 I/O pins
- System clock 8MHz (default fuse setting: divided by 8)
- 0 - 2 MHz @ 1.8 - 5.5V, 0 - 8 MHz @ 2.7 - 5.5V
Tool Chain/Development Environment
We will make use of WinAVR, which provides the GCC compiler that we will use; AVR Studio 4, which provides the integrated development environment we will develop on. In addition, we will also need TeraTerm for debugging purpose. We will use UART (Universal Asynchronous receiver/transmitter) serial communication to output data to the Terminal.WinAVR
Download and install WinAVR from the following URL:
http://winavr.sourceforge.net
AVR Studio 4
Download and install AVR Studio 4 and Service Pack 3 from the following URL: http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725TeraTerm
Download and install TeraTerm from the following URL: http://hp.vector.co.jp/authors/VA002416/teraterm.htmlTool Chain/Development Environment
We will make use of WinAVR, which provides the GCC compiler that we will use; AVR Studio 4, which provides the integrated development environment we will develop on. In addition, we will also need TeraTerm for debugging purpose. We will use UART (Universal Asynchronous receiver/transmitter) serial communication to output data to the Terminal.WinAVR
Download and install WinAVR from the following URL: http://winavr.sourceforge.netAVR Studio 4
Download and install AVR Studio 4 and Service Pack 3 from the following URL: http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725TeraTerm
Download and install TeraTerm from the following URL: http://hp.vector.co.jp/authors/VA002416/teraterm.htmlTool Chain/Development Environment
We will make use of WinAVR, which provides the GCC compiler that we will use; AVR Studio 4, which provides the integrated development environment we will develop on. In addition, we will also need TeraTerm for debugging purpose. We will use UART (Universal Asynchronous receiver/transmitter) serial communication to output data to the Terminal.WinAVR
Download and install WinAVR from the following URL: http://winavr.sourceforge.netAVR Studio 4
Download and install AVR Studio 4 and Service Pack 3 from the following URL: http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725TeraTerm
Download and install TeraTerm from the following URL: http://hp.vector.co.jp/authors/VA002416/teraterm.htmlGetting Started
Before writing any programs, we need to setup the hardware and connect it to your PC.Step1: Connect device card to STK600
Put the device card on the STK600 and lock it as shown in the picture below.Step2: Connect JTAG cable
Then, connect the JTAG programming interface using a 10-wire cable as shown in the picture below.Step3: Connect USB
Finally, connect STK 600 to your PC using the USB cable and turn the power switch to on.Before we really get started...
Note: When we first time connect the STK600 to PC, AVR Studio may ask you to update firmware. Click OK.Setting connection between STK600 and PC
After opening AVR Studio4, click on the connect icon.Select STK600 as the programmer and USB as the port, then click on Connect.
In the Main tab, select JTAG as the programming interface.
Now, we are ready to write some program.
Programming on STK600-ATMega2560
Create Project and Compilation
Create ProjectSelect AVR Simulater as the debug platform and ATmega2560 as the target device
Write some program
We can add source files or header files by right click on the folders.
To compile/build the project, Press F7 , or Build -> Build
Uploading to target device
Finally, we can upload the program (HEX file) after we build the project. Click on the "Connect to the selected AVR programmer" icon.Then, in the Program tab, check "Input HEX file" in the Flash panel and click "..." to browse the project folder for the HEX file
A file dialog pops for choosing the HEX file. The HEX file is located in "default" under the project folder.
Selecte the HEX file and click "Program".
But I want Eclipse...
Folks who dislike the build-in editor of AVR Studio, do not worry. There is a Eclipse AVR plugin. The Eclipse AVR will work with WinAVR and uploads programs using AVRDude. Unfortunately, uploading in Eclipse with STK600 does not work properly. See:1.Link 1
2.Link 2
We'll get back to this and try to get it working.
Example programs
The following programs require connecting corresponding I/O ports or cables.Blinking a LED
The following is a simple program that lits LEDs/* File: main.c */ #include <avr/io.h> int main(void) { // Set Data Direction of PORTB to output DDRB = 0xFF; // Set all pins to 1 (LEDs are active low) PORTB = 0xFF; PORTB = ~(_BV(PINB0) | _BV(PINB2) | _BV(PINB4) | _BV(PINB6)); }The following is a simple program that blinks LEDs
/* File: main.c */ #include <avr/io.h> #include <util/delay.h> int main(void) { DDRB = 0xFF; PORTB = 0xFF; for(;;) { PORTB = ~(_BV(PINB0) | _BV(PINB2) | _BV(PINB4) | _BV(PINB6)); _delay_ms(500); PORTB = 0xFF; _delay_ms(500); } }
Hello World
The following program demonstrate how to print message to TerminalFirst, you need to install TeraTerm and connect the STK600 to PC using RS232 cable.
Then copy uart.h and uart.c (UART driver) to the project folder and add them to "Header Files" and "Source Files".
Also, uart_test.c is the main program. The UART driver can be useful when debugging your project.
No comments:
Post a Comment