I have an Arduino Pro (8MHz/m328/3.3v) and wanted to use a serial baud rate that's higher than 57.6k. I realize that 115.2k and 230.4k aren't going to work as the "error" is too high. So, I tried to use 250k, as it has a 0% error in accordance with page 202 of the manual: http://www.atmel.com/Images/doc8161.pdf
Well, when I ran the following command to read outputted serial data:
screen /dev/tty.usbserial-A601EKZ6 250000
I get an endless supply of this:
Do I need to change something else before I can use this baud rate?
Thanks!
Aakash
PS. Here's the code I'm using. Basically, I need the higher baud rate so I can output data faster. I'm needing to transfer ~30bytes in about a millisecond and (10/57600)*30= ~5ms. So, 250000K might remedy this, as (10/250000)*30 = 1.2ms
better send the value of output binary as 4 bytes iso as text. Then you do not need to convert and it is less bytes to send.
now the unsigned long takes 8=12 chars,, while in fact you only need 4 bytes. (50-66% reduction.
the easiest way is to make a union of an array of 4 bytes and an unsigned long,
fill it as an UL and use the byte array for sending.
@robtillaart - Thanks for the suggestion! However, if I understand correctly, that will improve the performance of my current app at 57.6k. But, at that rate there is still a 3.5% error rate and the project I'm working will spit out a lot of data and needs to be accurate (it's for scientific data collection). The next lowest baud rate is 38.4k (0.2% error) and that's way too slow for my use as that 30 character figure I stated earlier might increase as I proceed with my project.
So my question remains - how can I get 250k baud rate working? I'm interested in the 500k baud rate as well (it has 0% error as well, according to the manual), but thought it would be wise to get the lower of the two rates working first.
The first thing to learn is if the problem is at the sending end or the receiving end. Do you have a oscilloscope or logic analyzer?
Also try to use another terminal program iso screen. Can the <?> chars be caused by reading an empty buffer?
Note that if the Crystal of the Arduino deviates a bit from the 8/16Mhz you can get an additional error.
You can try to compensate errors by using non standard baudrates e.g. 243000 (==250000 -3%) or 257000 baud. (trial and error is your friend)
tweaked the test code a bit to make it slightly faster. (~10% @115200baud)
robtillaart - Okay, so I used a logic analyzer with the Arduino set to various baud rates (9600, 19200, 38400, 57600, and 250000bps) and found something strange.
When using the following command on every test, excluding 250000, I was able to get "HELLO" printed repeatedly.
screen /dev/tty.usbserial-A601EKZ6 <BAUDRATE>
The strange part is that the logic analyzer was only able successfully show correct data on 9600bps.
Please see the attached files for the logic analyzer screenshot (excluding 19200, due to the attachment limit). The filenames correspond with the baud rate.
Is this a clock problem? If so, is my oscillator really that bad?
Why isn't the logic analyzer able to decipher the bytes correctly and gives those errors on the higher baud rates?
don't know, the signal seems OK, as I see quite some pulses.
Can you make some screen shots from this sketch, it will only send 4 bytes with distinct patterns (should fit on a screenshot) that should be recognizable at every baud rate.
The logic analyzer output looked great in all cases.
EDIT 1: Okay, so I tried using PuTTY on Windows inside of a VM and I got it to work at both 250000bps and 500000bps.
EDIT 2: I just tried with CoolTerm on OS X at 500000bps and it worked. Guess the screen command is just wonky.
So a question remains:
When measuring the loop-time at 250k and 500k using the sketch in my first post, they both got the same loop time (Around ~240-250 microseconds.) When adding more characters to each line [about 12 in total] and reading the state of a pin I get around 1100-1200 microseconds per loop in both (I measured that the logic, excluding the Serial.print(), takes around 240 microseconds). Why are these times the same? More importantly, would using an Arduino Uno @ 16MHz improve these times dramatically? What about the Arduino Due?
When measuring the loop-time at 250k and 500k using the sketch in my first post, they both got the same loop time (Around ~240-250 microseconds.)
...
Why are these times the same?
250Kbit => 25KB/sec = 40uSec/char
In theory 12 chars @250K => (at least) 500 usec for sending; @500K ==> 250 usec for sending,
so you must see differences. Can you post screen shots of the LA?
would using an Arduino Uno @ 16MHz improve these times dramatically? What about the Arduino Due?
An Arduino UNO =16Mhz and it would do everything except the actual transmit twice as fast as a 8 Mhz, so you should get loop times of about 600usec.
A DUE is 80+Mhz so 10x faster so loop times of 150 usec might be possible but I dont have much Due experience.
EDIT 2: After looking closely, I noticed that it took ~150 microseconds at 250k and ~120 microseconds at 500k. I didn't have a serial console attached during these tests. Why is there such a huge gap in time between each byte? Would buying the faster Due remedy this?