multiple serial ports on SAMD

Hi,
I want to use multiple modules (bluetooth, GPS, etc) in my project.
On the nano mkr1010 there is 1 hardware serial port (on pins 13,14)

As far as I can see, there are at 4 Serial controller (banks?) on board, where
1 is used on pins 0,1 (USB),
1 is used on pins 13,14 (Serial1)

How can I use the other 2? I found a snippet which claims to use pins 4,5, but I dont get it to work.

Does someone know documentation on how to use mutliple serial ports?
Thank you

may be this doc would be of interest

Adafruit also has a tutorial: Overview | Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports | Adafruit Learning System

Unfortunately, I already knew these tuts, but i gave it another shot. Without success.

I post here the modified code of the ublox GPS example, which is working fine on Serial1, but as soon as I change to Serial3 it doesnt work.
Maybe someone can spot the problem

/******************************************************************************
u-blox_GNSS.h
u-blox GNSS Arduino
Leonardo Bispo
Mar 03, 2019
https://github.com/ldab/u-blox_GNSS

Distributed as-is; no warranty is given.
******************************************************************************/
#include <Arduino.h>                              // required before wiring_private.h
#include <Wire.h>
#include <wiring_private.h>

// Enable Serial debbug on Serial UART to see registers wrote
#define GNSS_DEBUG Serial
#include "ublox_GNSS.h"

Uart Serial3 (&sercom4, 5, 4, SERCOM_RX_PAD_3, UART_TX_PAD_2);

float lat, lon, acc;

fixType_t fix = NO_FIX;

#define gps (Serial3)      //if this is Serial1 and I change the wiring accordingly everything works just fine

GNSS gnss( gps );



void setup() {
  // put your setup code here, to run once:
  Serial.begin( 115200 );
  
  pinPeripheral(4, PIO_SERCOM);   // Assign pins 4 & 5 SERCOM functionality
  pinPeripheral(5, PIO_SERCOM);
  
  gps.begin( 9600 );
 
  if( gnss.init(  ) )
  {
    Serial.println("\nGNSS initialized.");
  }
  else
  {
    Serial.println("\nFailed to initialize GNSS module.");
  }

}

void loop()
{
  // Get coordinates with minimum 100m accuracy;
  Serial.println("Get location");

  if ( gnss.getCoodinates(lon, lat, fix, acc, 100) == 0) 
  {
    Serial.println("Failed to get coordinates, check signal, accuracy required or wiring");
  }

  Serial.println("\nHere you are, lon:" + String(lon, 7) +" lat:" + String(lat, 7));
  Serial.println("calculated error: " + String(acc) + "m");
  
  Serial.println("\nOr try the following link to see on google maps:");
  Serial.println(String("https://www.google.com/maps/search/?api=1&query=") + String(lat,7) + "," + String(lon,7));

  delay(50000);

}

thank you

The SAMD21 has six SERCOMs. On the MKR WiFi 1010, it looks like:

0: used for I2C (Could be UART if you don't use I2C)
1: used for SPI (Could be UART if you don't use SPI)
2: SPI to WiFi interface (not usable)
3: not currently used. Potentially provides UART on pin 0/1.
4: MAYBE UART on pins 4/5?
5: Serial1 UART on pins 13/14

Pin 0/1 are NOT connected to USB as they would be on an AVR; the SAMD21 has dedicated USB hardware.

In your attempt I don't see you creating a SERCOM4_Handler() function?

That is correct. If I do, i got an error about duplicate methods

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