UART, I2C, and SPI

The RFzero is based on the SAMD21J18G 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 aliasGeneric nameRFzero useExternal pins
SerialGPSSerial1GPS serial link -none-
WireLocalWire1 Local I2C bus -none-
SerialSerial2Default UARTTX: A4, RX: A5
WireWire4 Default I2CSDA: D8, SCL: D9
SPISPI5Default SPIMISO: 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 nameSignalRFzero pin
Serial (UART)TXA4
RXA5
Wire (I2C)SDAD8
SCLD9
SPIMISOD16
MOSID18
SCKD19

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 useName (I2C)Name (UART)Name (SPI)SERCOM
GPS link - not available -SerialGPS (Serial1) - not available -4
Local I2C busWire1 (WireLocal)
- not available - - not available -3
Default UARTWire2Serial (Serial2)SPI20
(spare)Wire3Serial3SPI32
Default I2CWire (Wire4)Serial4SPI41
Default SPI - not available -Serial5SPI (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 signalRFzero pinRFzero MCU pinArduino Zero/M0 pins
TXD18PA22A4
RXD19PA23A5

Below is a simple “Hello World” example using the default Serial port.

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 nameSignals: TX, RXDeviceRFzero note
Serial1 = SerialGPS - no external pins -Sercom4Dedicated serial connection to the GPS module. Not available outside PCB
Serial2 = SerialA4, A5Sercom0Default
Serial3D4, D5Sercom2Must be initialized manually
Serial4D8, D9Sercom1Must be initialized manually
Serial5D18, D19Sercom5Must 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.

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.

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.

In the setup() function in the .ino file.

In the beginning of all the other .cpp files where the Serial5 port is used.

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 signalRFzero Pin/PortArduino Zero or M0 pins
SDAD8/PA16SDA/PA22
SCLD9/PA17SCL/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 namePins: SDA, SCLDeviceRFzero note
WireLocal (Wire1) - no external pins -SERCOM3Internal I2C bus on board. Not available outside PCB
Wire2D0, D1SERCOM0Must be initialized manually (see below)
Wire3D4, D5SERCOM2Must be initialized manually
Wire (Wire4)D8, D9SERCOM1Default

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).

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:

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 signalPin/PortArduino Zero/M0 pinout
MOSID164 (SPI connector)
SSD17Not assigned
MISOD181 (SPI connector)
SCKD193 (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 mameSignals: SCK, MISO, MOSIDeviceRFzero note
SPI2A3, A4, A5SERCOM0Must be initialized manually (see below)
SPI3D5, D6, D4SERCOM2Must be initialized manually (see below)
SPI4D9, D10, D8SERCOM1Must be initialized manually
SPI5D19, D16, D18, (D17)SERCOM5Default

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.

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.

Arduino nameArduino numberUARTSPII2CConnectorOther use that may conflict
A3A3Serial2SPI2JP4Analog input, Rotary input
A4A4Serial2SPI2JP4Analog input, Rotary input
A5A5SPI2JP4Analog input, Rotary input
D00Wire2JP5/JP6Open collector driver
D11Wire2JP5/JP6Open collector driver
D44Serial3SPI3Wire3JP5/JP6Open collector driver
D55Serial3SPI3Wire3JP5/JP6Open collector driver
D66SPI3JP5/JP6Open collector driver
D88Serial4SPI4Wire4JP11
D99Serial4SPI4Wire4JP11
D1010SPI4JP11/JP12HD44780 LCD header
D1717SPI5JP10
D1818Serial5SPI5JP10
D1919Serial5SPI5JP10

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.

SERCOMReserved useI2C nameSerial nameSPI name
0Wire2
SDA: D0, SCL: D1
Serial (Serial2)
TX: A4, RX: A5
SPI
SCK: A3, MISO: A4, MOSI: A5
1Wire (Wire4)
SDA: D8, SCL: D9
Serial4
TX: D8, RX: D9
SPI4
MOSI: D8, SCK: D9, MISO: D10
2Wire3
SDA: D4, SCL: D5
Serial3
TX: D4, RX: D5
SPI3
MOSI: D4, SCK: D5, MISO: D6
3EEPROM and
SI5351A
WireLocal (Wire1)
SDA: D30, SCL: D31
4GPSSerialGPS (Serial1)
TX: D32, RX: D33
5Does not existsSerial5
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 SPI2
RFzero pinMCU name/pinSerial2SPI2Wire2
A3PA05 / 10SCK
A4PA06 / 11TXMISO
A5PA07 / 12RXMOSI
D0PA08 / 13SDA
D1PA09 / 14SCL
Pinout for Serial3, Wire3 or SPI3
RFzero pinMCU name/pinSerial3SPI3Wire3
D4PA12 / 21TXMOSISDA
D5PA13 / 22RXSCKSCL
D6PA14 / 23MISO
Pinout for Serial4, Wire4 or SPI4
RFzero pinMCU name / pinSerial4SPI4Wire4
D8PA16 / 25TXMOSISDA
D9PA17 / 26RXSCKSCL
D10PA18 / 27MISO
Pinout for Serial5 or SPI5
RFzero pinMCU name/pinSerial5SPI5
D17PB03 / 48SCK
D18PB22 / 37TXMISO
D19PB23 / 38RXMOSI

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.