Hello. I am attempting to redirect some of the pins on the MKRZero board so I can use multiple serial communication methods at the same time. I am running into a problem when trying to make SERCOM2 into a UART. I feel like the solution is simple, but I could be wrong. Any help is appreciated!
Here is my code:
//puts TX on PA10 D1 - SERCOM2.2
//puts RX on PA11 D0 - SERCOM2.3
#include <Arduino.h> //required before wiring_private.h
#include "wiring_private.h" //pinPeripheral() function
Uart Serial2 (&sercom2, 0, 1, SERCOM_RX_PAD_3, UART_TX_PAD_2);
void SERCOM2_Handler()
{
Serial2.IrqHandler();
}
void setup()
{
Serial.begin(9600);
Serial2.begin(9600);
//assign pins 0 &1 SERCOM functionality
pinPeripheral(0, PIO_SERCOM_ALT); //use ALT b/c pin 3 and 4 use SERCOM alt mux
pinPeripheral(1, 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);
}
And here is the error message I am receiving:
Arduino: 1.8.12 (Windows 10), Board: "Arduino MKRZERO"
core\variant.cpp.o:(.bss.Serial2+0x0): multiple definition of `Serial2'
sketch\Sercom2_to_UART.ino.cpp.o:(.bss.Serial2+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino MKRZERO.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Here is the document I am following when trying to do this: