4.2 Atmel Studio with STK600
Prerequisites
- Atmel Studio 7.0 1645 or above installed
- The STK600 board connected to Atmel Studio 7.0 via the on-board USB connector.
Workflow
- Launch Atmel Studio 7.0.
- Start creating a new project by clicking New → Project... or by using the shortcut Ctrl+Shift+N, as shown in the figure below.
- Select the GCC C Executable Project
template from the new project wizard shown in the following figure, type in the name of the
solution and project (e.g. GETTING_STARTED and LED_TOGGLE), and click
OK.
- Select ATmega4809 from the device selection wizard as shown in the
figure below, and click OK.
main.c
file associated with it will be generated in Atmel Studio. - Replace the ‘
main
’ function in themain.c
file with the following code snippet:
In the code editor, the code may appear as shown in the figure below.int main (void) { /* STK600 have eight User Buttons and eight User LEDs which can be connected to any IO pin using cables */ /* Configure PB0 as input (remember to connect SW0 to PB0 using a cable */ PORTB.DIRCLR = PIN0_bm; /* Configure PB1 as output (remember to connect LED0 to PB1 using a cable*/ PORTB.DIRSET = PIN1_bm; while (1) { /* Check the status of SW0 */ /* 0: Pressed */ if (!(PORTB.IN & (PIN0_bm))) { /* LED0 on */ PORTB.OUTCLR = PIN1_bm; } /* 1: Released */ else { /* LED0 off */ PORTB.OUTSET = PIN1_bm; } } }
- Open project properties by clicking Project → Properties or by using the shortcut ALT+F7.
- In Tool view (figure below), set Selected debugger/programmer to STK600 and Interface to UPDI.
- Build the project by clicking Build → Build Solution or using the shortcut F7.
- Connect the embedded debugger on STK600 to ATmega4809 by connecting a cable between the ISP/PDI headers, as shown in the figure below.
- Connect PB2 to SW0, and PB5 to LED0 by using cables.
- Load the code onto the STK600 and start debugging by clicking Debug → Start debugging and break or by using the shortcut ALT+F5. The application is programmed onto the device and the program execution should break in main.
- Run the code by clicking Debug → Continue or by using the shortcut F5.
- Verify that LED0 is lit when SW0 is pushed on STK600.