Skip to content

Serial1.flush() blocks if called after Serial1.begin() and before port is written to. #140

Closed
@nsted

Description

@nsted

Caused problems while working on RS485 project on Arduino Zero. I flushed the port when switching between RX and TX mode, including at startup (ie before data is sent), which caused the program to block.


Test:

void setup() {
  Serial1.begin(9600); 
  SerialUSB.begin(9600);

//  Serial1.write(1);           // uncomment to prevent blocking

  SerialUSB.flush();            // doesn't block
  Serial1.flush();              // blocks everything below if called after Serial1.begin() and before any data sent.

  delay(2000);
  Serial1.println("Serial1 up and running");  
  SerialUSB.println("SerialUSB up and running");
  delay(3000);
}

int i;

void loop() {
  // put your main code here, to run repeatedly:
  Serial1.println(i++);
  SerialUSB.println(i);
}

The issue appears to be tied to this method:

void SERCOM::flushUART()
{
  // Wait for transmission to complete
  while(!sercom->USART.INTFLAG.bit.TXC);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions