Table of contents
The RFzero is based on the SAMD21G18A micro controller that has six SERCOM interfaces available, each of which can be configured for one of the Serial UART, SPI or I2C protocols. In contrast to the smaller Arduino Uno compatible devices, the USB port is not part of the SERCOM subsystem and can thus be used independently no matter how the configuration is.
If you are just here to the find detailed pinout, you may want to jump directly to the pinout tables or the allocation configuration below.
If you need a more general description of the SERCOM interface of SAMD21 under the Arduino environment, see the Communications page under Tutorials. For detailed information and examples, check out the pages for the Serial UART, the I2C Wire or the SPI tutorials.
You can also keep reading to make yourself an overview of the flexible communication possibilities of the RFzero 🙂
Quick overview
On the RFzero board two of the SERCOM units have already been dedicated to the GPS module link and the local I2C bus for the EEPROM and Si5351A. The four remaining SERCOM ports can be configured for external connection in numerous way according to your communication needs.
The table below gives a quick overview of the default configuration. These are the communication ports that always are available and can be used without further configuration. (Unless, of course, you change the configuration manually as described below.)
Popular alias | Generic name | RFzero use | External pins |
---|---|---|---|
SerialGPS | Serial1 | GPS serial link | -none- |
WireLocal | Wire1 | Local I2C bus | -none- |
Serial | Serial2 | Default UART | TX: A4, RX: A5 |
Wire | Wire4 | Default I2C | SDA: D8, SCL: D9 |
SPI | SPI5 | Default SPI | MISO: D16, MOSI: D18, SCK: D19 |
Each protocol function (Serial, Wire, SPI) has been given a default SERCOM device and pin allocation. However, this behavior is quite easily overwritten manually in the programming code, see below.
Arduino name | Signal | RFzero pin |
---|---|---|
Serial (UART) | TX | A4 |
RX | A5 | |
Wire (I2C) | SDA | D8 |
SCL | D9 | |
SPI | MISO | D16 |
MOSI | D18 | |
SCK | D19 |
Manual configuration
If you want a communication setup other than the default one in the above table, you need to configure it manually.
The table below shows an overview of the six SERCOM units and the possible configuration options for external communication. The default configuration is highlighted with boldface.
RFzero use | Name (I2C) | Name (UART) | Name (SPI) | SERCOM |
---|---|---|---|---|
GPS link | - not available - | SerialGPS (Serial1) | - not available - | 4 |
Local I2C bus | Wire1 (WireLocal) | - not available - | - not available - | 3 |
Default UART | Wire2 | Serial (Serial2) | SPI2 | 0 |
(spare) | Wire3 | Serial3 | SPI3 | 2 |
Default I2C | Wire (Wire4) | Serial4 | SPI4 | 1 |
Default SPI | - not available - | Serial5 | SPI (SPI5) | 5 |
These are the available RFzero SERCOM configurations which have been carefully chosen for optimal versatility. It is unlikely you should need to change it unless you are really pushing the limits. However, if you insist and you know how to do it, there is still a few pins left you can switch around. Taking a look at the variant.h and variant.cpp files — as well as the SAMD21 datasheet — will get you started.
See the individual sections on Serial, Wire or SPI for information on how to change the setup.
Serial (UART)
Up to four external serial links may be used at a time –that is, if you don’t need the remaining SERCOMs for other communication purposes, e.g. I2C or SPI. One is always present and the others will have to be configured manually.
The default Serial interface
The default serial port is called Serial and is configure and ready from startup. All you have to do to use it is initialize it with the Serial.begin() function call just like most other Arduino compatible boards. The signals are available on A4 (TXD) and A5 (RXD) as illustrated in the following table.
Serial signal | RFzero pin | RFzero MCU pin | Arduino Zero/M0 pins |
---|---|---|---|
TX | A4 | PA6 | A4 |
RX | A5 | PA7 | A5 |
Below is a simple “Hello World” example using the default Serial port.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// RFzero include and object creation #include <RFzero.h> // MUST ALWAYS be included for RFzero void setup() { // Initialize Serial, also the same as Serial2 Serial.begin(9600); // Set the Serial port to 9600 Baud and 8N1 (default) Serial.println("Hello World - here is RFzero"); } void loop() { } |
Setting up additional Serial ports
The ports are named from Serial1 to Serial5 as shown in the following table of the port pinouts of which Serial1 is already dedicated to the GPS link. The table below sums up the ports.
Interface name | TX | RX | Device | RFzero note |
---|---|---|---|---|
Serial1 = SerialGPS | N/A | N/A | Sercom4 | Dedicated serial connection to the GPS module. Not available outside PCB |
Serial2 = Serial | A4 | A5 | Sercom0 | Default |
Serial3 | D4 | D5 | Sercom2 | Must be initialized manually |
Serial4 | D8 | D9 | Sercom1 | Must be initialized manually |
Serial5 | D18 | D19 | Sercom5 | Must be initialized manually (see below) |
Please note that Serial1 (the GPS module link) and Serial2 (the default serial port) have been given the aliases SerialGPS and Serial for convenient referencing.
In order to use Serial ports 3, 4 or 5, they will have to be enabled first by declaring the UART in the top of your sketch (.ino) file. This is preferably done right after the inclusion of the RFzero header file. In brief, to enable Serial5, include the following line at the top of your sketch.
1 2 3 |
// enable UART no 5 (Serial5) Uart Serial5(&PERIPH_SERIAL5, PIN_SERIAL5_RX, PIN_SERIAL5_TX, PAD_SERIAL5_RX, PAD_SERIAL5_TX) ; void SERIAL5_IT_HANDLER() { Serial5.IrqHandler(); } |
The above code lines contain a number of macros that have been predefined in the RFzero environment to make it convenient to enable Serial5. Getting the pin numbers and pad assignments of the serial port configurations correct is a little tricky which is why a similar set of macros exists for each serial port.
So, in short, to enable either Serial3, Serial4 or Serial5 instead, simply include the above line, taking care to change all the macros to represent the correct port.
1 2 3 |
// ** replace # with the desired number 3-5 ** Uart Serial#(&PERIPH_SERIAL#, PIN_SERIAL#_RX, PIN_SERIAL#_TX, PAD_SERIAL#_RX, PAD_SERIAL#_TX) ; void SERIAL#_IT_HANDLER() { Serial#.IrqHandler(); } |
As it is also the case with I2C and SPI, you cannot arbitrarily choose the pins and define your own macros since the SAMD SERCOMs only support a certain set of pin positions. The pinouts chosen above have been chosen for optimal versatility and you really should not need to change it. However, if you insist on meddling and you know how to do it, taking a look at variant.h and variant.cpp –as well as the SAMD21 datasheet– will get you started.
Adding an extra serial port to the an example programs
If you want to add an extra serial port to one of the example programs you must apply the above steps the program. Below is how this is done in the PI4 + CW + carrier example program for Serial5.
In the beginning of the .ino file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
... // RFzero include and object creation #include // MUST ALWAYS be included for RFzero #include // Only relevant if CW or a MGM is needed #include // Adds some general purpose functions // Add Serial5 Uart Serial5(&PERIPH_SERIAL5, PIN_SERIAL5_RX, PIN_SERIAL5_TX, PAD_SERIAL5_RX, PAD_SERIAL5_TX) ; void SERIAL5_IT_HANDLER() { Serial5.IrqHandler(); } // Program includes. Located in the same directory as this .ino file #include "global.h" #include "config.h" #include "commands.h" ... |
In the setup() function in the .ino file.
1 2 3 4 5 6 7 8 9 10 11 |
... // Setup USB SerialUSB.begin(9600); delay(2000); // Delay used instead of "while (!(SerialUSB));" because it halts if not connected to USB. Checks show up to 1 s so 2 s to be on the safe side // Setup Serial5 Serial5.begin(9600); // Load configuration if (RFzero.eeprom_isUnconfig()) ... |
In the beginning of all the other .cpp files where the Serial5 port is used.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
... // Program includes. Located in the same directory as the .ino file #include "global.h" #include "config.h" #include "commands.h" uint8_t configMode = 0; // Indicates if program is in config mode uint8_t configChanged = 0; // Indicates if the configuration has changed extern Uart Serial5; void ParseCommand(char *str) ... |
I2C (Wire)
Default I2C interfaces is called Wire in Arduino and is configured and ready to go from startup. Don’t forget to connect the pull-up resistors from SDA and SDC to the 3,3 V supply. 4,7 kΩ to 10 kΩ will work in most cases.
I2C signal | RFzero Pin/Port | Arduino Zero or M0 pins |
---|---|---|
SDA | D8/PA16 | SDA/PA22 |
SCL | D9/PA17 | SCL/PA23 |
Please note that if your I2C device(s) use 5 V you will need a 3,3 V to/from 5 V level converter that can be made either by discrete components, ready made board or an IC. Please see the Third party accessories section on the Shop page.
Make sure to check out the examples on the I2C tutorial page. For more information about the I2C bus please see the application report from Texas Instruments: Understanding the I2C Bus.
Setting up additional I2C ports
In total four wire interfaces (I2C) are available of which Wire1 is occupied for the internal bus (WireLocal) and Wire4 already is configured as the default (Wire). However, Wire2 and Wire3 have been prepared for use and can easily be enabled. See the following table for an overview of the RFzero pinouts for each Wire interface. Keep in mind that you can only configure a new I2C port if the corresponding SERCOM unit is not already in use.
Interface name | SDA | SCL | Device | RFzero note |
---|---|---|---|---|
WireLocal (Wire1) | N/A | N/A | SERCOM3 | Internal I2C bus on board. Not available outside PCB |
Wire2 | D0 | D1 | SERCOM0 | Must be initialized manually (see below) |
Wire3 | D4 | D5 | SERCOM2 | Must be initialized manually |
Wire (Wire4) | D8 | D9 | SERCOM1 | Default |
For instance, to make Wire2 available, all you have to do is include the following lines at the top of your sketch (preferably right after including the RFzero library).
1 2 |
TwoWire Wire2(&PERIPH_WIRE2, PIN_WIRE2_SDA, PIN_WIRE2_SCL) ; void WIRE2_IT_HANDLER(void) { Wire2.onService(); } |
Here, PERIPH_WIRE2 and the other upper case names are macros that have been predefined in the RFzero variant configuration to make it convenient to automatically assign the correct pins and SERCOM device. Equivalent to the above example, you can initialize Wire3 using the predefined macros:
1 2 |
TwoWire Wire3(&PERIPH_WIRE3, PIN_WIRE3_SDA, PIN_WIRE3_SCL) ; void WIRE3_IT_HANDLER(void) { Wire3.onService(); } |
You cannot arbitrarily choose the pins and define your own macros since the SAMD SERCOMs only support a certain set of pin positions.
SPI
The SPI is a four wire full duplex interface that allows multiple devices, named master and slave(s), to use the same four wires to send and receive data to and from the master or slave. The bus clock can vary from circuit to circuit.
SPI signal | Pin/Port | Arduino Zero/M0 pinout |
---|---|---|
MISO | D16 | 4 (SPI connector) |
SS | D17 | Not assigned |
MOSI | D18 | 1 (SPI connector) |
SCK | D19 | 3 (SPI connector) |
The four wires are called Master Out Slave In (MOSI), Master In Slave Out (MISO), Serial ClocK (SCK) and Slave Select (SS). The SS is seldom used if there is only one slave connected to the master.
Setting up additional SPI ports
While SPI5 is the default SPI port, the other ports may be enabled if you are not using the corresponding SERCOM for other purposes. Below is shown the possible pinout allocations.
Interface name | MISO | MOSI | SCK | Device | RFzero note |
---|---|---|---|---|---|
SPI2 | A4 | A5 | A3 | SERCOM0 | Must be initialized manually (see below) |
SPI3 | D6 | D4 | D5 | SERCOM2 | Must be initialized manually (see below) |
SPI4 | D10 | D8 | D9 | SERCOM1 | Must be initialized manually |
SPI5 | D16 | D18 | D19 | SERCOM5 | Default |
To enable, for instance, SPI2 include the first two lines in the below code box. The lines should by in the top of your sketch file, preferably right under the RFzero.h inclusion.
1 2 3 4 5 6 7 8 |
// include to enable SPI2 on pins A3, A4, A5 SPIClass SPI2 (&PERIPH_SPI2, PIN_SPI2_MISO, PIN_SPI2_SCK, PIN_SPI2_MOSI, PAD_SPI2_TX, PAD_SPI2_RX); // include to enable SPI3 on pins D4,D5,D6 SPIClass SPI3 (&PERIPH_SPI3, PIN_SPI3_MISO, PIN_SPI3_SCK, PIN_SPI3_MOSI, PAD_SPI3_TX, PAD_SPI3_RX); // include to enable SPI4 on pins D8,D9,D10 SPIClass SPI4 (&PERIPH_SPI4, PIN_SPI4_MISO, PIN_SPI4_SCK, PIN_SPI4_MOSI, PAD_SPI4_TX, PAD_SPI4_RX); |
Similarly, you can enable SPI3 or SPI4 by including the relevant lines from the above list.
While the line to include do have macros that refer to the relevant pin numbers, you cannot arbitrarily choose the pins and define your own macros since the SAMD SERCOMs only support a certain set of pin positions.
SERCOM allocation planning
Since each SERCOM unit can only serve one protocol (Serial, SPI or I2C) at a time, great care has been taken to arrange the RFzero pinout for maximum flexibility. The table below shows possible pin allocations for each SERCOM unit and what other RFzero functions that may overlap in pin assignment.
RFzero name | RFzero number | UART | SPI | I2C | Connector | Other use that may conflict |
---|---|---|---|---|---|---|
A3 | A3 | Serial or Serial2 | SPI2 | JP4 | Analog input, Rotary input | |
A4 | A4 | Serial or Serial2 | SPI2 | JP4 | Analog input, Rotary input | |
A5 | A5 | SPI2 | JP4 | Analog input, Rotary input | ||
D0 | 0 | Wire2 | JP5/JP6 | Open collector driver | ||
D1 | 1 | Wire2 | JP5/JP6 | Open collector driver | ||
D4 | 4 | Serial3 | SPI3 | Wire3 | JP5/JP6 | Open collector driver |
D5 | 5 | Serial3 | SPI3 | Wire3 | JP5/JP6 | Open collector driver |
D6 | 6 | SPI3 | JP5/JP6 | Open collector driver | ||
D8 | 8 | Serial4 | SPI4 | Wire4 | JP11 | |
D9 | 9 | Serial4 | SPI4 | Wire4 | JP11 | |
D10 | 10 | SPI4 | JP11/JP12 | HD44780 LCD header | ||
D17 | 17 | SPI5 | JP10 | |||
D18 | 18 | Serial5 | SPI5 | JP10 | ||
D19 | 19 | Serial5 | SPI5 | JP10 |
Note that the RFzero board still contains another 3 analog pins and 9 digital I/O pins that are not shown in the above table which may be used for other purposes without conflicting with your allocation of SERCOM devices.
Detailed pinout reference tables
Below is a compact table that sums up the RFzero pin assignments for each SERCOM configuration option.
SERCOM | Reserved use | I2C name | Serial name | SPI name |
---|---|---|---|---|
0 | Wire2 SDA: D0, SCL: D1 | Serial (Serial2) TX: A4, RX: A5 | SPI SCK: A3, MISO: A4, MOSI: A5 |
|
1 | Wire (Wire4) SDA: D8, SCL: D9 | Serial4 TX: D8, RX: D9 | SPI4 MOSI: D8, SCK: D9, MISO: D10 |
|
2 | Wire3 SDA: D4, SCL: D5 | Serial3 TX: D4, RX: D5 | SPI3 MOSI: D4, SCK: D5, MISO: D6 |
|
3 | EEPROM and SI5351A | WireLocal (Wire1) SDA: D30, SCL: D31 | ||
4 | GPS | SerialGPS (Serial1) TX: D32, RX: D33 | ||
5 | Does not exists | Serial5 TX: D18, RX: D19 | SPI (SPI5) MISO: D16, MOSI: D18, SCK: D19 |
The below tables detail the pinout for each device configuration along with the intrinsic processor pins. Note that it is not possible to use the same device for different protocols even though the pins do not overlap.
Pinout for Serial2, Wire2 or SPI2RFzero pin | MCU name/pin | Serial2 | SPI2 | Wire2 |
---|---|---|---|---|
A3 | PA05 / 10 | SCK | ||
A4 | PA06 / 11 | TX | MISO | |
A5 | PA07 / 12 | RX | MOSI | |
D0 | PA08 / 13 | SDA | ||
D1 | PA09 / 14 | SCL |
RFzero pin | MCU name/pin | Serial3 | SPI3 | Wire3 |
---|---|---|---|---|
D4 | PA12 / 21 | TX | MOSI | SDA |
D5 | PA13 / 22 | RX | SCK | SCL |
D6 | PA14 / 23 | MISO |
RFzero pin | MCU name / pin | Serial4 | SPI4 | Wire4 |
---|---|---|---|---|
D8 | PA16 / 25 | TX | MOSI | SDA |
D9 | PA17 / 26 | RX | SCK | SCL |
D10 | PA18 / 27 | MISO |
RFzero pin | MCU name/pin | Serial5 | SPI5 |
---|---|---|---|
D17 | PB03 / 48 | SCK | |
D18 | PB22 / 37 | TX | MISO |
D19 | PB23 / 38 | RX | MOSI |
The USB interface
The Universal Serial Bus (USB) is a two wire interface bus that allows many devices to communicate with each other. The communication speed is typically in the same range as the UART but can go up to 12 Mb/s.
The USB interface is called SerialUSB and with DP on D28/pin 33 and DM on D29/pin 34.