How to program Arduino Due using ATMEL Studio

In this tutorial we show how you can write a basic LED blinking program in AMTEL Studio for Arduino Due. Arduino Due is a powerful board with lots of features and functions due to ARM cortex 32 bit processor. In order to utilize its full power you may want to write programs in C or C++ using ATMEL Studio.

In this tutorial you will learn how to program Arduino Due using ATMEL Studio. In order to follow this tutorial you must have Arduino IDE and ATMEL Studio installed. Also in this tutorial example we have used the Arduino IDE v1.8.0 and ATMEL Studio 7. But other versions should also work. If not leave comment and we will try to help you solve the problem. If you don’t know where and how to download and install the programs see our previous tutorial How to program Arduino using ATMEL Studio 7. Note that in that tutorial we have used Arduino UNO board.

Before you can learn how to program Arduino Due using ATMEL Studio you need to configure a programmer for Arduino Due as an external tool in ATMEL Studio. This external tool is basically a compiler toolchain that ATMEL studio will use in order to compile the C or C++ program and upload it to the Arduino Due. The bassac.exe is used in case of Arduino Due whereas in case Arduino UNO, avrdude.exe is used.

Steps for how to program Arduino Due using ATMEL Studio

The steps to configure ATMEL studio, write, compile and upload the hex file to Arduino Due are as follows.

  1. Configure ATMEL Studio External Tool for Arduino Due
  2. Create New ASF project
  3. Writing LED Blinking Program
  4. Build, Compile and Upload

1. Configure ATMEL Studio External Tool for Arduino Due

Creating a programmer for Arduino Due is the first step. ATMEL studio allows users to add external compiler chain to it via the External Tools. Four our case, we need the Arduino Due Bassac compiler to add as an external tool. This step shows how to add bassac.exe as external tool so that you can  program Arduino Due using ATMEL Studio.

To configure the external tool, open ATMEL studio and open External Tools by going to Tools > External Tools…Then fill up the command and argument fields as follows.

Title: Arduino Due Programmer

Command: C:\Users\sinu\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino/bossac.exe
Arguments: -i -d –port=COM9 -U false -e -w -b $(TargetDir)$(TargetName).bin -R

Note

  1. The part C:\Users\sinu above will be different for your computer.
  2. The COM9 will be different for your computer.
  3. You can any Title name.

See the following picture of this setting.

External Tool setting for Arduino Due

Then when you Click on Tools on the toolbar you should see the Arduino Due Programmer as shown below.

Now your Programmer is ready to be used after we have written the led blinking program.

2. Create New ASF Project

The next step is to create ASF project. There are different alternative to create ASF project for Arduino Due. Here we show how to create ASF project that utilizes the inbuilt Arduino Due Board so that the hardware configuration and initialization is minimized to the user. The other option is to create ASF project where user can just specify the microprocessor on the custom board. In this case, hardware initialization is required. Tutorial utilizing custom board will be shown in another tutorial.

Create a new Project by going to File> New Project. You will see a screen that shows the different types of projects options available to you. Select GCC C ASF Board Project, provide some project name like LEDBlink, Location for your project, and Solution to Create New Solution as shown below.

Click on OK.

Now in the next window that appears, we will select the Arduino Due board. First select Select By Board, then in the search field type Arduino and you should see the Arduino Due/X ATSAM3X8E board. This is as shown below.

How to program Arduino Due using ATMEL Studio

Click on OK.

Now ATMEL studio creates a project and it looks like the following.

The main window is showing main.c program code. This can be opened after you src folder on the right pane then click on the main.c file.

The content of the main.c is empty with bare minimum code and comments.

Now next we show how to write C program for LED blinking and then how to program Arduino Due using ATMEL Studio.

3. Writing LED Blinking Program

To write a led blinking program we have to add some functions. One function is a toggle function called ioport_toggle_pin_level() which toggles the LED ON and OFF given the pin name of the LED. The other one is a function that creates delay which is called delay_ms() which takes integers as argument for millisecond. The last one is called the sysclk_init() function which is required to set up the clock for the delay.

These functions are available once you have the proper ASF services. For sysclk_init() and ioport_toggle_pin() you don’t need to add any service because during the project creation for Arduino board it was already added. The delay routine service however must be added so that we can use the delay_ms() function.

To add the delay service we use the ASF Wizard where we can search various services or modules made available to us by ATMEL ASF project. Click on the ASF Wizard under the ASF in the toolbar. See below.

ASF Wizard

Then in the window that shows up type delay in the search field. You should see the Delay routines(services). Add it by clicking on the Add>> button.

Then you should see the Delay routines(services) in the Selected Modules pane.

Click Apply and click OK on the summary window that pops up.

Now you can use the delay_ms() function.

Now type the following in the main.c program file.

sysclk_init(); before the board.init() function within the int main(void). In the while(1) loop use the ioport_toggle_pin_level(LED0_GPIO); to toggle the LED at pin 13 on arduino board. And finally use delay_ms(100); for delay between LED ON and LED OFF.

The following is the complete main.c code.

4. Build, Compile and Upload

The final step is to build, compile and upload the program code to Arduino Due. Click on Build > Build Solution. Then after successful build, click on Tools > Arduino Due Programmer.

At this point the LED at pin 13 should be blinking. See the following video demonstration.

 

This tutorial showed you how to program Arduino Due using ATMEL Studio 7. For programming Arduino UNO see How to program Arduino using ATMEL Studio 7.

What do you think?

0 points
Upvote Downvote

Total votes: 0

Upvotes: 0

Upvotes percentage: 0.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

2 Comments

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Arduino Due

Arduino Simulink S-function tutorial

LED blinking C program for Arduino

LED blinking C program for Arduino