Fast serial over USB

Hi, I've read that it's possible to run the serial faster than 115200 bps (e.g. here http://forum.arduino.cc/index.php/topic,21497.0.html ). I've tried to do it on the Due and Uno, but it doesn't produce the expected results: the data are corrupted if I write too fast, and if I add a delay between writes (writing 514 bytes then sleeping >10msec), it works, but writing is as slow as on 115200 -- not just because of the delays, but the writes seem to block. I have some questions to make sure I'm doing it right:

  • Is this possible for the serial over USB connection to run at high speeds e.g. 115200*4= 460800 bps?
  • Which is most likely to work, Uno, Due prog. port or Due native port? (maybe off topic) - Does JSSC support such baud rates?

There may be bugs in the code causing the corrupted data, but I hope someone can say wheter it should be possible in the first place. The project is for controlling 264 RGB LEDs, and I'd like at least 30 updates per second.

The problem is, that standard baud rates gives you bad values in the serial registers. The UBBR register of the ATmega16U2 gets this value:

#define SERIAL_2X_UBBRVAL(Baud) ((((F_CPU / 8) + (Baud / 2)) / (Baud)) - 1)

For your 460800 bps this gives 3.84 or in integer: 3. So the effective bps are 571429 which is quite different from the requested value. Then if this value is set, your processor gets interrupted every 17┬Ás, doing quite a bunch of stuff. The interrupt handler is quite slick so it should end rather fast but if there is any other thing done in interrupt context, the handling might be too late and data gets corrupted. I guess you might get that to work on the Due but you have to adapt the baud rates to get a better register value in the ATmega16U2.

better try "multiples" of the 16MHz clock - 500000 or 250000 works quite well (not with the IDE serial monitor BTW)

This may be helpful:

http://www.wormfood.net/avrbaudcalc.php

Thanks for the help. It worked with 500000 and 1000000 baud, on both the Uno and Due. I ended up with using an ethernet shield because the program coulnt' handle updating fast enough with the serial connection.