5

I am trying, unsuccessfully to communicate, using my Arduino Nano, with a custom device at a baud rate of 800 kbit/s.

The Arduino code look like this:

void setup() {
  // Put your setup code here, to run once:
  Serial.begin(800000);
}

void loop() {
  // Put your main code here, to run repeatedly:
  delay(5000);
  Serial.println(0x2be1);
}

When I am trying to debug it with PuTTY the result is:

PuTTY output @ 800 kb/s

And when I change the baud rate to 400 kbit/s the result is (as it should be):

PuTTY output @ 400 kb/s

Any idea?

Greenonline
  • 3,152
  • 7
  • 36
  • 48
user28282
  • 55
  • 1
  • 5

1 Answers1

13

The Arduino Nano cannot do 800 kb/s. As you can see in the source code, the bit duration is rounded to the nearest multiple of 8 CPU cycles. In your case, it is rounded to 3 × 8 CPU cycles, which yields a baud rate of 666.666 kb/s. That is 16% too slow, an error too large for any communication to be possible.

At 400 kb/s there is no rounding error, so everything works fine.

Edit: Note that if you build your own barebones Arduino, then either a 12.8 MHz or a 19.2 MHz crystal should allow you to get that exact baud rate. But then millis(), delay() and co. would all be off.

Edgar Bonet
  • 45,094
  • 4
  • 42
  • 81