Serial0 vs Serial1 slow speed on Teensy4

Status
Not open for further replies.

groowla

New member
Hi, I was playing around with Serial0 and Serial1 and I've noticed that for some reason Serial1 is much much slower than Serial0.
I'm quite new to teensy but this seems a little strange, unless I'm missing something?

Basically I print 9999 entries through Serial0 and it takes 17ms,
however the same code on Serial1 takes around 14000ms .... I'm not sure whats happening there ?
Something blocking?
Thanks for you replies.

code:
Code:
char data[17] = { "12345670HelloWd" };
unsigned long time1, time2, time3;

void setup() {
  Serial.begin(115200);
  Serial1.begin(115200);
  delay(1000);
}

void loop() {
  time1=millis();
  
  runloop1();    
  gettime();
  
  Serial.println(time3);

  time1=millis(); //update time
  
  runloop2();
  gettime();
  
  Serial.println(time3);

  delay(5000);
}

void gettime() {
  time2=millis();
  time3=time2-time1;
}

void runloop1(){
  for (int i = 0; i < 9999; i++)
    { 
      Serial.println(data);
    }   // end of for loop
}


void runloop2(){
  for (int i = 0; i < 9999; i++)
    { 
      Serial1.println(data);  
    }  
}
 
On most if not all Teensy boards (I have not looked at Teensy 1) The Serial object is not a hardware UART, but instead points to USB serial IO...

The Baud rate is more or less ignored as you are simply putting thing into a USB buffer, and when appropriate a USB Packet is sent to the host.

Whereas Serial1 IS a hardware Serial port. And it will output Serial data on actual IO pins. In this case on Pin 1 at the speed you specified in the Serial1.begin.
 
Yup, sending 169,983 characters at 115200 baud on Serial1 should take about 14.7 seconds. Each character is 10 bits (1 start, 8 data, 1 stop), so Serial1 can send 11520 bytes per second.

As Kurt explained, Serial ignores the baud rate number and runs at the maximum USB speed. 169,983 bytes in 0.017 seconds is approx 10 Mbyte/sec. Factoring in USB protocol overhead, that's about 20% of the 480 Mbit/sec USB speed.

Future versions of Teensyduino will have more USB optimization to reduce that 17 ms. :)
 
Status
Not open for further replies.
Back
Top