ATSAMD21G custom board - Help with pin assigment

Hi..
I am about to finalise my first SAMD21 based board and I am puzzled with the different pin uses found in different designs. For example SPI , I2C pins differ between Arduino zero, arduino zero mkr and other adafruit boards.

I know that Atsamd21 chips have 6 configurable IO ports that can be setup as either spi, i2c, uart etc but how does the hardware connections chosen (pcb cannot change once made!) are later reflected in software? eg when the wire.h or SPI.h library is used which pins will it access?

Please see below my current pin assignment.
The chip drives a 3.5 SPI connected tft touch screen, a rotary enocoder and has onboard rs485 interface (RX,TX labels) and an i2c eeprom.

Any comments welcome..

Hi Watcher,

The board pin assignments are made in the Arduino "variants.h" and "variants.cpp" files. I'd check those out first before sending your custom board out for manufacture.

The files (on my Windows machine) can be found here:

C:\Users\Computer\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.11...

From here just enter the "variants" directory and choose the board you're basing your design on.

It's possible to create you own "variant" files and create a new entry for your board in the Arduino IDE, but if you can is easier to just match your boards's pin assignments one of the Arduino's. In that way, you'll also benefit from any Arduino core code updates that occur from time to time.

Thank you.

So pins get used based on that file and the bootloader chosen to burn.

One more question: PB22 and PB23 are used in Arduino Zero to talk to the embedded debugger which in my case doesn't exist. Same for a few other pins. Can these pins be used for other purpose?

Hi Watcher

So pins get used based on that file and the bootloader chosen to burn.

Yes that's right, unless you modify the variant files and/or the bootloader.

One more question: PB22 and PB23 are used in Arduino Zero to talk to the embedded debugger which in my case doesn't exist. Same for a few other pins. Can these pins be used for other purpose?

Yes, PB22 and PB23 can be used for other purposes, but on the Arduino Zero you just have to bear in mind that these are configured as a serial port by the bootloader during the boot process. These pins become GPIO once the microcontroller starts the sketch. On my Zero based custom board, I just used these pins as the DC (data/control) and RESET outputs for an OLED display, since the display doesn't care if these pins are toggled during an upload.

On other SAMD21 based boards, this won't be the case as they don't have the EDBG debugging chip.

The same goes for the Zero's TX and RX LEDs outputs during an upload.

In any case, if the PB22/PB23 serial port or the TX/RX LEDs are an issue, it's possible to modify and recompile the bootloader source code, to disable/deactive them.

I guess it just depends on how closely you custom board matches whichever board you're basing it on. Usually, matching it relatively closely makes things a bit easier.

Thanks for the valuable info.

I ve been desiging all my customs boards based on atmega1284p so far. This is the first time am "upgrading" to this chip since I need more power.

So my inderstanding now is that it wont be possible to access simultaneously two separate hardware SPIs from the arduino IDE. Only the one that matches the arduino chosen. Correct?

Which arduino config would you advice me to adopt? The zero or maybe the zero mkr ? Or maybe some other?

Apart from all the digital pins than I need for the display and other SPI CS signals , I also need a hardware RS232 port as well as I2C lines.

Hi Watcher,

So my inderstanding now is that it wont be possible to access simultaneously two separate hardware SPIs from the arduino IDE. Only the one that matches the arduino chosen. Correct?

No, actually it's possible to call on two (or even three) separate hardware SPI ports from the Ardiuno IDE. Calling on the SPI library with the line:

#include <SPI.h>

...will automatically create an SPI C++ object on the default pins, defined in the "variant.h" file. However, it's possible to use one of the SAMD21's spare SERCOM (serial communication) modules to create further hardware SPI, Serial or I2C ports.

Creating additional hardware SPI, Serial or I2C ports is described in this Adafruit tutorial: Overview | Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports | Adafruit Learning System.

Which arduino config would you advice me to adopt? The zero or maybe the zero mkr ? Or maybe some other?

In your schematic, it looks like you're currently following the Arduino Zero pattern. I noticed that TXD and RXD are using SERCOM5 on PB22 and PB23, I think this should be fine, if there are issues on this port with the bootloader, it would be possible modify it in any case.

In general, if you're planning on using most of the microcontroller's pins, I'd go with the Arduino Zero, but this can depend on other factors such as board layout constraints. Also, most of the SAMD21 boards from Sparkfun (SAMD21 Dev and Mini Breakout boards) and Adafruit (Metro, Isty Bitsy and Feather M0) match the pinouts of the Arduino Zero as well. Arduino started to diverge from this standard layout later on with their MKR family.

In my opinion, having standard layout is important. It means that code developed on the Arduino Zero can then easily be ported to a smaller board such as an Adafruit Itsy Bitsy M0. Unfortunately, Adafruit's SAMD51 boards (Itsy Bitsy, Metro and Feather M4), now each have different pin assignments making this impossible.

Thank so much for your help!

Here's a 3D impression of my board with the screen:


..and with a smaller 2.2 inch screen

Capture3.JPG

Capture3.JPG

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.