Hi,
I'm not sure if this the normal behavior, but if I try to check Serial1.available() it always returns >0, even when nothing is connected to the rx and tx pins (0 and 1).
Here is a simple test sketch
void setup() {
Serial1.begin(115200);
pinMode(7, OUTPUT);
}
void loop() {
if(Serial1.available()>0)
{
digitalWrite(7, HIGH); //always high
}
else
digitalWrite(7, LOW);
}
Edit: it seems to be some kind of noise, if I do Serial1.read() once, it solves the problem and stays at 0.
Another question is, whats the default state of the tx and rx pins when not in use? If I measure it with a voltmeter they are low by default.
Edit2: It seems that TX and RX pins are always low (0v) even if I'm writing something using Serial1.write.
Silly me, I was using the wrong pins. I was using the I2c pins, no wonder I didn't get any output.
Now here comes the real question:
Im in a situation where I need to use D20, D21 pins (SDA and SCL) for UART serial com.
Basically I need to convert the I2C Sercom3 pins to UART serial.
I have read the posted tutorials on how to create a new Serial, and this is what I have so far.
Uart Serial2 (&sercom3, 21, 20, SERCOM_RX_PAD_1, UART_TX_PAD_0);
void SERCOM2_Handler()
{
Serial2.IrqHandler();
}
setup()
{
Serial2.begin(115200);
}
It doesnt seems to work, if I call Serial2.write or print it crashes.
Sercom3 on the samd21 are as follow
PA22 D20 / SDA SERCOM3.0 SERCOM5.0
PA23 D21 / SCL SERCOM3.1 SERCOM5.1
Edit: Answering my own question, use
pinPeripheral(21, PIO_SERCOM);
pinPeripheral(20, PIO_SERCOM);
in setup().