๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Feather M4 Express SERCOM
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather M4 Express SERCOM

by Ddahl08 on Fri Jun 14, 2019 7:12 pm

Can someone please post an example of a working SERCOM for the M4 feather. It seems that following the "Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports" in the Learn section does not work with the M4.

I would like Serial2 on the SDA and SCL pins.

SCL pin 22 - RX - sercom2.1
SDA pin 21 - TX - sercom2.0

Ddahl08
 
Posts: 5
Joined: Mon Jan 23, 2017 4:57 pm

Re: Feather M4 Express SERCOM

by timdriedger on Fri Jun 28, 2019 2:55 pm

Did you ever figure this out?

I'm also wanting to add additional serial ports to my Feather M4 for a project.
timdriedger
 
Posts: 5
Joined: Tue Jul 09, 2013 1:52 am

Re: Feather M4 Express SERCOM

by timdriedger on Fri Jun 28, 2019 3:43 pm

I found a combination that worked for Sercom 0...

Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>
#include "wiring_private.h"

Uart Serial2 (&sercom0, A5, A4, SERCOM_RX_PAD_2, UART_TX_PAD_0);

void SERCOM0_0_Handler() {
  Serial2.IrqHandler();
}

void SERCOM0_1_Handler() {
  Serial2.IrqHandler();
}

void SERCOM0_2_Handler() {
  Serial2.IrqHandler();
}

void SERCOM0_3_Handler() {
  Serial2.IrqHandler();
}

void setup() {
  Serial.begin(115200);
  Serial2.begin(115200);
  pinPeripheral(A5, PIO_SERCOM_ALT);
  pinPeripheral(A4, PIO_SERCOM_ALT);
}

uint8_t i = 0;

void loop() {
  Serial.print(i);
  Serial2.write(i++);
  if (Serial2.available()) {
    Serial.print(" -> 0x"); Serial.print(Serial2.read(), HEX);
  }
  Serial.println();
  delay(10);
}
Last edited by timdriedger on Fri Jun 28, 2019 3:48 pm, edited 1 time in total.
timdriedger
 
Posts: 5
Joined: Tue Jul 09, 2013 1:52 am

Re: Feather M4 Express SERCOM

by timdriedger on Fri Jun 28, 2019 3:48 pm

And another for Sercom 4...

Code: Select all | TOGGLE FULL SIZE
#include <Arduino.h>
#include "wiring_private.h"

Uart Serial2 (&sercom4, A3, A2, SERCOM_RX_PAD_1, UART_TX_PAD_0);

void SERCOM4_0_Handler() {
  Serial2.IrqHandler();
}

void SERCOM4_1_Handler() {
  Serial2.IrqHandler();
}

void SERCOM4_2_Handler() {
  Serial2.IrqHandler();
}

void SERCOM4_3_Handler() {
  Serial2.IrqHandler();
}

void setup() {
  Serial.begin(115200);
  Serial2.begin(115200);
  pinPeripheral(A3, PIO_SERCOM_ALT);
  pinPeripheral(A2, PIO_SERCOM_ALT);
}

uint8_t i = 0;

void loop() {
  Serial.print(i);
  Serial2.write(i++);
  if (Serial2.available()) {
    Serial.print(" -> 0x"); Serial.print(Serial2.read(), HEX);
  }
  Serial.println();
  delay(10);
}
timdriedger
 
Posts: 5
Joined: Tue Jul 09, 2013 1:52 am

Please be positive and constructive with your questions and comments.