SAMD21 Mini/Dev Breakout Hookup Guide
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.
Feature | ATSAMD21G18A | ATmega328P |
---|---|---|
Architecture | ARM Cortex-M0+ | AVR |
Bus Size | 32-bit | 8-bit |
Max CPU Speed | 48MHz | 20MHz |
Flash | 256KB | 32KB |
SRAM | 32KB | 2KB |
EEPROM | 32KB (emulated in Flash) | 1KB |
Voltage Range | 1.62-3.63V | 1.8-5.5V |
GPIO Count | 38 | 23 |
ADC Channels | 14 | 8 |
ADC Resolution | 12-bit | 10-bit |
Digital-to-Analog Converter (DAC) | Yes | No |
USB Controller | Yes | No |
Direct Memory Access (DMA) | 12 Channels | No |
Peripheral Touch Controller | Yes | No |
Inter-IC Sound I2S | Yes | No |
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.
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):
SERCOM0 | SERCOM1 | SERCOM2 | SERCOM3 | SERCOM4 | SERCOM5 | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
PAD0 | A3 | D4 | RTC1 | D11 | D4 | MISO | D11 | SDA | MISO | A1 | SDA | A5 |
PAD1 | A4 | D3 | RTC2 | D13 | D3 | D38 | D13 | SCL | D38 | A2 | SCL | RXLED |
PAD2 | D8 | D1 | SWCLK | D10 | D1 | D2 | D10 | D6 | MOSI | D2 | D30 | D6 |
PAD3 | D9 | D0 | SWDIO | D12 | D0 | D5 | D12 | D7 | SCLK | D5 | D31 | D7 |
Arduino Default | Dev Board Only (Not broken out on Mini) | In-Use | ||||||||||
|
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!
For more information about adding more SERCOM ports for your SAMD-based board, check out the tutorial below.
Adding More SERCOM Ports for SAMD Boards
February 4, 2019
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!