SAMD21 Mini/Dev Breakout Hookup Guide

Pages
Contributors: jimblom
Favorited Favorite 4

SAMD21 Overview

Atmel’s ATSAMD21 (the ATSAMD21G18A to be exact) is a 32-bit ARM Cortex-M0+ microcontroller, which means it’s world’s different from the 8-bit AVR’s you may be familiar with. Comparing the SAMD21 against our old favorite – the ATmega328P – isn’t very fair, but we’re going to do it anyway.

FeatureATSAMD21G18AATmega328P
ArchitectureARM Cortex-M0+AVR
Bus Size32-bit8-bit
Max CPU Speed48MHz20MHz
Flash256KB32KB
SRAM32KB2KB
EEPROM32KB (emulated in Flash)1KB
Voltage Range1.62-3.63V1.8-5.5V
GPIO Count3823
ADC Channels148
ADC Resolution12-bit10-bit
Digital-to-Analog Converter (DAC)YesNo
USB ControllerYesNo
Direct Memory Access (DMA)12 ChannelsNo
Peripheral Touch ControllerYesNo
Inter-IC Sound I2SYesNo

Okay…mercy rule. This isn’t to say there aren’t benefits to the ATmega328’s: they’re well-documented, have huge support in the community, are simpler to wrap your head around, and can operate at 5V. There’ll always be a place in the world for the ATmega328P, but – especially as price point’s get closer – there are many good reasons to consider the SAMD21.

This page will discuss some of the features that make the SAMD21G18 a unique step above the ATmega328P.

ARM Cortex-M0, 32-bit, 48MHz, Lots of Memory

If you’ve ever run into the program storage limits of an Arduino Uno, felt hampered by an Arduino Pro Mini’s 8MHz operating speed, or had to troubleshoot those mysterious dynamic memory (SRAM) stack overflows, you may know why the SAMD21’s larger memory-capacities are so exciting.

The SAMD21’s 256KB of flash means you shouldn’t ever have to worry about fitting your compiled sketch into a tight 32KB space. That extra flash can be used to store large, user-defined blocks of data as well, with libraries like FlashStorage.

SAMD21 Memory Map

The memory map of an ATSAMD21, complete with 0x40000 (262,144) bytes of code memory!

The SAMD21 will process your instructions much faster too. Not only can it run at more than double the speed of an AVR, but it’s also helped by the 32-bit architecture. While the AVR has to divide processing of large data types into 8-bit sections, the SAMD21 can process large blocks of data in single, fell swoops.

SERCOM – Configurable Serial Ports

One of the most unique features of the SAMD21 is SERCOM – a set of six configurable serial interfaces that can be turned into either a UART, I2C master, I2C slave, SPI master or SPI slave.

Each SERCOM provides for a lot of flexibility: the ports can be multiplexed, giving you a choice of which task each pin is assigned. Here’s an overview of which pins can be configured to which SERCOM interface (the pins names have been Arduino-ified):

SERCOM0SERCOM1SERCOM2SERCOM3SERCOM4SERCOM5
PAD0A3D4RTC1D11D4MISOD11SDAMISOA1SDAA5
PAD1A4D3RTC2D13D3D38D13SCLD38A2SCLRXLED
PAD2D8D1SWCLKD10D1D2D10D6MOSID2D30D6
PAD3D9D0SWDIOD12D0D5D12D7SCLKD5D31D7
Arduino DefaultDev Board Only
(Not broken out on Mini)
In-Use
  • USB-D- can be assigned SERCOM3:2 or SERCOM5:2
  • USB-D+ can be set to SERCOM3:3 or SERCOM5:3
But they're so much more useful as USB data lines! (And they'd ruin our table formatting.)

In the Arduino IDE, SERCOM0 and SERCOM5 are assigned to UARTs (laying claim to pins 0, 1, 30, and 31 respectively), SPI defaults to SERCOM4 (pins MISO, MOSI, and SCLK), and I2C is SERCOM3 (SDA and SCL). That leaves SERCOM1 and SERCOM2 that you can bend to your will – make pins 3 and 4 I2C, or turn pins 10-13 back into SPI (like the good, old days).

With the ability to create multiple UARTs or other serial interfaces, you may never have to bitbang SPI, or debug around SoftwareSerial again!

USB Controller

Like the ATmega32U4 on the Arduino Leonardo and SparkFun Pro Micro, the ATSAMD21 is equipped with an integrated USB controller. It can be used as either a USB device or host.

In device mode, the SAMD21 can emulate a keyboard, mouse, or joystick, work as a mass storage device, or communicate as if it were a serial port. Device mode is a critical part of the SAMD21’s USB-programmability. It configures itself as a USB CDC (communication device class), so your computer can talk to it as if it were a serial port.

As a USB host, the SAMD21 can connect up to a keyboard or mouse, or even save data to a USB flash drive. It takes some extra power-supply-planning to get the SAMD21 to work as a USB host, but it can be a rewarding component of your project.

Clocks – RTC and Timer-Counter

Almost every pin on the SAMD21 is tied to a timer-counter, which means you’ll see a lot more PWM-capable I/O pins. In fact, all digital pins besides D2 and D7 can be used with the analogWrite function. You’ll have plenty of options for dimming LEDs or controlling motor drivers.

Real time clocks (RTC) can be critical components in projects that need precise time-keeping – whether it’s for creating a digital clock or a controlled PID loop. While the ATmega328 does have an RTC, you’ll need to sacrifice clock cycles for time-keeping, by swapping out the 16MHz crystal for one running at 32.768kHz. The SAMD21 has a separate real-time clock system, powered by an on-board 32.768kHz crystal, and it still clocks the processor at 48MHz.

Analog-to-Digital and Digital-to-Analog Converters (ADC & DAC)

The SAMD21G18 has 14 total ADC input pins, each with 12-bit resolution. That increased resolution means every bit between 0 and 4095, represents about 0.806mV (assuming the processor is powered at 3.3V), allowing for more sensitive voltage measurements. Analog reference pins are also available, if you need to further fine-tune the ADC system.

The SAMD21 also features a digital-to-analog converter (DAC) output, for creating truly analog signals. The DAC has up to 10-bit resolution, and can convert up to 350,000 samples per second (350ksps). The analog output pin is shared with the Arduino “A0” pin – it’s the only one you get, so use it wisely!