Serial not working above 19200 baud

I have a sketch (attached) which is reading analog values on ADC pin 0 and streaming data to the host computer. The sketch works perfectly for baud rates of 9600, and 19200, but I get no data when I try rates over 19200 such as 38400, 115200, etc…

Oh, I have tried the communication with the internal terminal in the Arduino IDE, minicom, and a python script. They all fail above 19200 baud…

I have tried this on a UNO R3, MEGA R3, and Duemolova, and NG rev 3, all with the same results. However, all of those boards have no problem sending serial data at 115,200 baud when using different sketches… All of this is using the same host computer, running Ubuntu 12.04

TRNG_USB.ino (8.25 KB)

What's your definition of failing here? Does it send garbage? Do you get nothing at all?

Attached? I see no sketch.

pylon:
What's your definition of failing here? Does it send garbage? Do you get nothing at all?

I see no characters displayed in minicom, in the arduino terminal the horizontal scroll bar moves but nothing is displayed, my python script fails to connect

MarkT:
Attached? I see no sketch.

It is an attachment to the post.

i’ve tested it on my arduino too, and i got the same results, there’s only one thing… did you notice it does send information to the pc when running on a baudrate higher than 19200? it’s only empty chars (ASCII<32), and therefore you don’t see them (i think), but it does send something

it works the same on all the baudrates

Steen:
i’ve tested it on my arduino too, and i got the same results, there’s only one thing… did you notice it does send information to the pc when running on a baudrate higher than 19200? it’s only empty chars (ASCII<32), and therefore you don’t see them (i think), but it does send something

it works the same on all the baudrates

So are you saying that you are getting <ASCII 32 when you run the sketch at all baud rates?

The sketch displays the following start-up text for me when the baud rate is either 9600 or 19200, but not above that

Avalanche Noise Random Number Generator
version 1.0
by Walter Anderson

Starting Calibration
Finishing Calibration
Ready"

yep, that’s what it shows (it also shows 1000100 or something like that)

well, i made a quick “serial monitor” that shows the decimal ascii numbers of the input it gets, and this was the output in Ascii decimal numbers:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

that means you’re sending data, but only nulls, which is nothing in fact… in normal mode (baud<=19200) this is the output (as it should be):

49 48 48 48 48 49 48 48 10 65 118 97 108 97 110 99 104 101 32 78 111 105 115 101 32 82 97 110 100 111 109 32 78 117 109 98 101 114 32 71 101 110 101 114 97 116 111 114 10 118 101 114 115 105 111 110 32 49 46 48 10 98 121 32 87 97 108 116 101 114 32 65 110 100 101 114 115 111 110 10 32 10 83 116 97 114 116 105 110 103 32 67 97 108 105 98 114 97 116 105 111 110 10 70 105 110 105 115 104 105 110 103 32 67 97 108 105 98 114 97 116 105 111 110 10 82 101 97 100 121 10

i have no clue how this could come… really nothing xs

Could it be that analogRead behaves a bit differently depending on the frequency you call it and causes different values to be printed? On lower baud rates there is longer delay between analogReads. Try to add some delay in the loop and check what happens.

analogread is not affected by changing the baudrate, or at least it should not be...

just to point again, those 0's are not zero's like no voltage is read, it is a zero in ascii code, which means null, and that means b00000000 is sent, or 0x00 or however you want to say it :slight_smile:

It of cource had nothing to with the analogRead, stupid me :frowning:

The real problem is this:

const int baud_rate = 38400;

The max value of signed integer is 32768.

pekkaa:
It of cource had nothing to with the analogRead, stupid me :frowning:

The real problem is this:

const int baud_rate = 38400;

The max value of signed integer is 32768.

... I hate myself sometimes...

Got the code working up to 460,800 baud... Thanks to everyone for helping this fool...

lol

that's all i can say to this :slight_smile:
and what do you say? 460800 bps? can the arduino do that?

Switching off compiler warnings for such code

const int baud_rate = 38400;

is a big flaw of arduino IDE.

460800 bps? can the arduino do that?

I heard that Serial.begin(500000); were even better, because it matches the internal clock frequency.

Steen:
lol

that's all i can say to this :slight_smile:
and what do you say? 460800 bps? can the arduino do that?

I've seen reports of the arduino achieving 2,000,000 baud albeit with a small degree of data loss (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1242967991)

In my case, I can get up to 460,800 baud, but it doesn't look like I will need to go that high since, it didn't seem to make much difference in total throughput. I'm guessing that the Serial library may be interrupt driven and therefore the speed limit in my case is being set by the speed with which I can construct the byte stream.

wanderson:

MarkT:
Attached? I see no sketch.

It is an attachment to the post.

Ah, invisible to me today for some reason - code tags are less hassle for us BTW, no need to save a file and open an editor.

michael_x:
I heard that Serial.begin(500000); were even better, because it matches the internal clock frequency.

1M, 500K, 250K, 125K, etcetera are all "zero error" baud rates for an AVR processor running at 16 MHz. I've used 250K exclusively for months with no problems.