Go Down

Topic: Serial1.available() always >0 (Read 380 times) previous topic - next topic

jojojijijojo

Jul 28, 2017, 11:27 pm Last Edit: Jul 29, 2017, 12:26 am by jojojijijojo
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
Code: [Select]

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.

jojojijijojo

#1
Jul 29, 2017, 03:17 am Last Edit: Jul 29, 2017, 03:23 am by jojojijijojo
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.
Code: [Select]

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

Code: [Select]

PA22   D20 / SDA   SERCOM3.0   SERCOM5.0
PA23   D21 / SCL   SERCOM3.1   SERCOM5.1


Edit: Answering my own question, use
Code: [Select]

 pinPeripheral(21, PIO_SERCOM);
  pinPeripheral(20, PIO_SERCOM);

in setup().

Go Up