Introduction to the Atmel SAMD21 Microcontroller

The SAMD21 series of microcontrollers are based on the ARM Cortex®-M0+ 32-bit processor. It operates at up to 48 MHz and comes with up to 256 KiloBytes of programmable flash. At Zippy Robotics, I've used the SAM4S MCU to control several prototypes of our PCB milling machine, Prometheus. However, I'm evaluating the SAMD21 as a replacement for this role and I thought I'd share some information that you might find useful as you think about your own projects.

In Atmel Studio 7, you'll find that 238 example projects are available for the SAM D21 Xplained Pro board. Nice!
238 example projects are available for the SAM D21 Xplained Pro board!
The SAMD21 has several things going for it - it's cheaper than Atmel's other ARM cores like the SAM4S, there is a wealth of information and documentation for it (both by Atmel and third parties), and it is very well supported in Atmel Studio with example projects. There are currently 238 example projects for Atmel's SAMD21 Xplained Pro evaluation kit. The value from the example projects cannot be overstated - combined with the Xplained Pro board, they get you up and running in no time. Additionally, if you're a fan of Arduino, you can develop your Arduino code for the Arduino Zero board which uses the SAMD21 MCU. You can also find Arduino-compatible boards based on the SAMD21 from companies like SparkFun and Adafruit.

Program your SAM D21 Xplained Pro Evaluation Kit

This part requires that you have your own SAM D21 Xplained Pro evaluation kit so you can follow along. You'll also need a USB cable (A to micro B); it's not included with the evaluation kit. If you haven't done so already, download and install Atmel Studio.


Open Atmel Studio and connect the Xplained Pro board to your PC via USB. The board has two USB ports; one is labeled "DEBUG USB", which is for debugging and programming with Atmel Studio, and the other is labeled "TARGET USB" and can be used if you're developing USB applications. In this case, we're just programming the board, so plug the USB cable into DEBUG USB. Atmel Studio should recognize the board and may prompt you that board's firmware is out of date. If that happens, update it before doing anything else by following the instructions Atmel Studio gives you.


When you're ready, go to the menu bar and click File > New > Project. From the popup that appears, select "GCC C ASF Board Project", give it a name if you'd like, and click OK. Next, you'll be prompted to select the board. We need to find the SAM D21 Xplained Pro board from the list. One way to do this is to click the "Select By Device" radio button and then type "SAMD21J18" into the search box. The list will filter and you can then find and select "SAM D21 Xplained Pro - ATSAMD21J18A". Then click OK and Atmel Studio will create the project.

new projboard selection

On the right you'll see a panel labeled "Solution Explorer". Navigate to "src > main.c" and double-click main.c to open it. We see the Atmel Studio has already created some skeleton code for us that we can modify. For the purpose of this tutorial, we won't modify it - we just want to get the default sample code onto the SAM D21's program memory. If we look at the comments and read the code, we can see that this sample code that Atmel Studio has created for us just turns on LED0 whenever we press Button 0, which is actually labeled "SW0" on the board for "switch 0". To program the board with our simple firmware, all we have to do is click the green play button. This is the "start without debugging" option and it will program the SAM D21 and then it will immediately begin executing it's code.

open main
Open "main.c", found here.
initial code marked up

Once you click "start without debugging", you will see the Output console pop up and eventually say "Build Succeeded" because the code is valid. If instead there were compilation errors, you would see those instead.

What you should see after pressing the play button.
If your project compiled successfully and you see "Ready" on the lower-left corner of the screen, you can now test your code. Push the SW0 button and you should see LED0 illuminate. Release it, and LED0 will go out. That's it! Simple. Now you can write your own code to suit your needs. We'll explore some more simple programming and the ASF (Atmel Software Framework) in future tutorials.

The following two tabs change content below.

Rocco Tuccio

Founder at Zippy Robotics, Inc
I'm the founder of Zippy Robotics and creator of Prometheus. I'm interested in electrical, mechanical, and software engineering and hold a bachelor of science in physics from the University of Maryland. Let's build something!

Latest posts by Rocco Tuccio (see all)

Leave a Reply