I want to use two serial Ports with Seeed Studio XIAO RP2040, but if i use Serial2 with defined pins and upload the compiled code to the device it freezes immediately.
So how can i use Serial1 default Pins (6/7) and Serial2 with custom pins?
not sure if it helps but using a Raspberry Pi Pico I had Serial1 working on pins GP0 and GP1 (default) just setting the baudrate
Serial1.begin(115200);
and Serial2 on GP4 and GP5 using setTX() and setRX() functions, e.g.
// Raspberry Pi Pico RP2040 Serial2 test - for loopback test connect pins Tx GP4 and Rx GP5
#include <Arduino.h>
// Note
// Serial is the USB serial for program loading and serial mointor
// there are two hardware serial ports UART0 and UART1
// Serial1 is mapped to UART0 on Rx pin GP1 Tx pin GP0
// Serial2 is mapped to UART1 on Rx pin GP5 Tx pin GP4
void setup() {
// initialize both serial ports:
Serial.begin(115200);
delay(2000);
// reassign pin numbers for Serial1
Serial2.setTX(4); // note cannot swap pins
Serial2.setRX(5);
Serial2.begin(115200);
Serial.println("\n\nRaspberry Pi Pico RP2040 serial2 test Rx pin GP5 Tx pin GP4 ");
Serial.write(" for loopback test connect pin GP4 to pin GP5\n");
}
void loop() {
// read from port 1, send to port 0:
if (Serial2.available()) {
int inByte = Serial2.read();
Serial.write('>');
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
//Serial.write(inByte);
Serial2.write(inByte);
}
}
when I attempted to use Serial2 on GP6 and GP7
// reassign pin numbers for Serial2
Serial2.setTX(6);
Serial2.setRX(7);
Serial2.begin(115200);
it failed and hangs the processor - have to reset using BOOTSEL button