Electronics

Adafruit FeatherM0 ASF Tutorials

The source code for the tutorials can be found on GitHub.

2017-07-04 00:56

01_Blink - Digital Output

As it is common practice, we start with the most simple application: Blinking a LED - The "Hello World" of embedded programming.

The schematic of Adafruit's FeatherM0_WiFi shows a LED on the ATSAMD21G18_QFN port PA17 (pin 26).


Schematic Source: Adafruit, License: Attribution-ShareAlike Creative Commons

The program should let this LED blink.

Creating the Atmel Software Framework (ASF) Skeleton Project

We start the software development by creating a GCC C ASF Board Project Skeleton in a new Adafruit_FeatherM0_ASF_Tutorials Solution for a User Board for the 01_Blink project.

See my Step-By-Step tutorial if you are not sure how to do this.

Adding the project specific Atmel Software Framework (ASF) code

The next step is to import the ASF modules needed for the specific project.

You should see two lists:

In Selected Modules we already see:

This is the standard framework needed for any ASF application.

For the LED to blink we need to control the PORT/Pin the LED is connected to.

But only switching on and off the LED pin in an endless loop, would make the LED blink so fast that we could not distinguish between the on and the off state. Therefore we want to delay the loop after each state change for 500ms.

So in Available Modules find:

And Add>> those to the project.

Now press Apply. This will add all the necessary ASF code to our project.

Using the DIT Adafruit Feather Library

During the tutorials (and maybe later for "real" applications) there is some information that is needed by several applications and some tasks that are common to them.

To avoid having to reimplement or copy this code all the time, it is common practice to create library files and reference those whenever needed in a project.

I created a couple of library files for working with the Adafruit FeatherM0, while writing the tutorials. You can find these files in the root directory of the solution (.c and .h files starting with Adafruit_FeatherM0_*).

You need to:

See my Step-By-Step tutorial if you are unsure how to do this.

Writing the application code

After all the preparation we finally now get to the point where we implement our application logic.

In the Solution Explorer find the generated main.c.

Here is the code that keeps the LED blinking.

All we need to import to get the whole ASF magic working is the asf.h, that was generated by the ASF wizard. The entry should already be there. The wizard took care of that for us.

In line 51 I include the Adafruit_FeatherM0_LED.h library header file.

This library provides us with:

In the main() function (lines 37..53) we first initialize the ASF modules:

If you forget one of those there is a good chance the LED won't blink (might stays on or off all the time though - been there, done that ;-) )

Everything done right, after programming the board, the LED should blink with an interval of 1s.