max baudrate

Hi,

what is the maximum baud rate on an arduino zero?

and how can I set this rate? SerialUSB.begin(baud);? And is this baud rate the same if I use rosserial? How to set it there?

Why should I use a baud rate which is not the maximum one? due to energy efficiency?

Thanks

On Zero the baud setting in SerialUSB.begin(baud) is ignored. To get the max baudrate use the 256000 on the PC side (that's the maximum serial baudrate supported by WinAPI). But to fully utilize that baudrate you need to send/receive data from Arduino in packets using SerialUSB.write(bufToSend, BufSize). I use packet size of 400, I don't know what is the max packet size but I found that increasing the packet above 400-500 does not noticeably affect the overall data transfer rate.

see also

to fully utilize that baudrate you need to send/receive data from Arduino in packets using SerialUSB.write(bufToSend, BufSize). I use packet size of 400

In a test program, I get SerialUSB Write speeds over 200kbps with a write size of one, 1.5Mbps with a write size of 5, 5.7Mbps with a write size of 30, and about 6Mbps with a size of 40, maxing out with a size of 60.
I suspect the USB “native packet size” is 64 bytes, and increasing the size of the Write over that doesn’t accomplish very much. (OTOH, SerialUSB.Println(12345678); only goes about 800kbps.)
So yes, outputting more than one byte at a time is helpful, but it isn’t necessary to use particularly LARGE
writes() to get performance significantly larger than you can get with a real serial port.

//#define Serial SerialUSB

void setup() {
  Serial.begin(250000);
  while (!Serial)
    ;
  Serial.print(F("Enter a character to select write size"));
}
char text[] = "  0123456789... ABCDEFGHIJKLMNOPQRSTUVWXYZ \n"
              "  0123456789 .... ABCDEFGHIJKLMNOPQRSTUVWXYZ \n"
              "  0123456789 .... ABCDEFGHIJKLMNOPQRSTUVWXYZ \n";

void loop() {
  uint32_t starttime, eltime, datasent;
  int c = Serial.read();
  if (c < 0)
    return;
  if (c >= '0') {
    int len;
    len = (c - '0') * 5;
    if (len == 0) len = 1;
    Serial.print("Serial.write speed test with size ");
    Serial.println(len);
    Serial.flush();
    starttime = micros();
    datasent = 0;
    while (1) {
      if (micros() - starttime > 1000000)
        break;
#if 1
      Serial.write(text, len);
      datasent += len;
#else
      Serial.println(123456L);
      datasent += 8;
//      datasent += sizeof("This is a test\n");
#endif
    }
    Serial.flush();
    eltime = micros() - starttime;
    Serial.println();
    Serial.println(F("Test done."));
    Serial.print(F("Serial.write speed test with size "));
    Serial.println(len);
    Serial.print(F("Sent "));
    Serial.print(datasent);
    Serial.print(F("bytes of data in "));
    Serial.print(eltime);
    Serial.println(F(" Microseconds"));
    Serial.print(F("Data Rate is "));
    Serial.print((datasent * 8e6) / eltime);
    Serial.println(" bps");
    Serial.println();
    Serial.print(F("Enter a character to select write size"));
    while (Serial.read() > 0)
      ;
  }
}

westfw:
In a test program, I get SerialUSB Write speeds over 200kbps with a write size of one, 1.5Mbps with a write size of 5, 5.7Mbps with a write size of 30, and about 6Mbps with a size of 40, maxing out with a size of 60.
I suspect the USB “native packet size” is 64 bytes, and increasing the size of the Write over that doesn’t accomplish very much.

westfw, good to know, thanks for the info. But how do you receive data at that speed on the PC side? I use serial port library in C++ on PC side and it only allows the max baudrate of 256000 on the PC side (which is the maxi serial baudrate for COM port supported by WinAPI as far as I know). (I know I can use a USB-COM adapter to get higher datarates but my device is USB powered and I’ll loose the USB power if I do that.)

how do you receive data at that speed on the PC side? I use serial port library in C++ on PC side and it only allows the max baudrate of 256000 on the PC side

With a native USB connection, what you SET the PC-side bit rate to shouldn't matter.
(I was using a Mac, with the Arduino "Serial Monitor" set to 9600bps, and the Arduino sketch set to 250kbps, getting the 4Mbps+ data rates.)
(I suppose that it's possible that the windows driver has some sort of internal rate-limiting, but it seems unlikely. Did you try it out?)

westfw:
With a native USB connection, what you SET the PC-side bit rate to shouldn't matter.
(I was using a Mac, with the Arduino "Serial Monitor" set to 9600bps, and the Arduino sketch set to 250kbps, getting the 4Mbps+ data rates.) (I suppose that it's possible that the windows driver has some sort of internal rate-limiting, but it seems unlikely. Did you try it out?)

Yes, I tried all possible baudrates higher than 250kbps on Windows and none of them worked. Then I read on some Microsoft page that 250kbps is the max limit for serial comm in WinAPI. I guess on Mac there must be no such limit if it worked for you.

No,no. You set the windows-side speed for 9600. It just goes faster than that!