Offline
Newbie
Karma: 0
Posts: 9
|
 |
« on: April 29, 2012, 02:32:04 pm » |
Having an problem with the 14400 baud rate on an Mega Board. With Serial1 Tx Connected to Rx the following code works on 9600 and 19200 baud rates but on 14400 the pulse width varies from bit to bit (from 50 to 100 uSec)
void Setup() { Serial.begin(14400); Serial1.begin(14400); }
void loop() { if( Serial.available()) { int inByte = Serial.read(); Serial1.write(inByte); }
if(Serial1.available()) { int inByte = Serial1.read(); Serial.write(inByte); } }
|
|
|
|
« Last Edit: April 29, 2012, 02:36:24 pm by T3bear »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 119
Posts: 10172
|
 |
« Reply #1 on: April 29, 2012, 04:03:36 pm » |
on 14400 the pulse width varies from bit to bit (from 50 to 100 uSec) How did you arrive at that conclusion?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #2 on: April 30, 2012, 10:33:20 am » |
I was watching the input and output pulses on a scope. The pulse width seems to right and consistent for 9600 and 19200 baud.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #3 on: April 30, 2012, 11:34:53 am » |
More Information-> I modified the code to send and receive on Serial. only at 14400 baud
loop() { if(Serial.available() { int inbyte = Serial.read(); Serial.write(inbyte); } }
Results-> Using the Serial Monitor-> sending 'r' or 'y' the return is 'r' or 'y' sending 'R' or 'Y' the return is 'r' or 'y' Upper case is returned as lower case sending a string of characters return trash again other baud rates work fine
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9414
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #4 on: April 30, 2012, 12:35:15 pm » |
I recall some trouble with 57600 baud .. but no other.
Which IDE are you using 1.0, 0.22, 0.23?
have you tried another version of the IDE?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #5 on: April 30, 2012, 01:13:58 pm » |
I am using IDE 1.0, will give another a try. Thanks
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #6 on: April 30, 2012, 01:51:30 pm » |
I tried IDE 0022 and got the same results Also tried 3 different Mega boards and 3 different Uno boards 14400 baud always the problem.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 119
Posts: 10172
|
 |
« Reply #7 on: April 30, 2012, 04:20:03 pm » |
What is the full frame time (start bit to stop bit) of a byte leaving the processor (pin 1 on the Uno)? Transmitting a zero will make the measurement easier... void loop( void ) { Serial.write( (byte)(0x00) ); delay( 1000 ); }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #8 on: April 30, 2012, 05:26:42 pm » |
Overall byte times @ 14400 baud> Overall time of a byte from PC/SerialMonitor = 875 uSec Overall time of a byte from UNO to PC/SerialMonitor = 835 uSec
The transmitted bits from the UNO are shorter than the bits from the PC
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 119
Posts: 10172
|
 |
« Reply #9 on: April 30, 2012, 05:37:02 pm » |
What frame time do you get at 9600 baud? What about 19200?
When sending a zero byte, is the frame is a continuous low signal?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #10 on: April 30, 2012, 08:14:01 pm » |
New byte times for 14400 baud: The Uno Tx pin is high is goes low for 625 uSec then return high(the previous value was in error) on incoming from PC the Rx is high and goes low for 725 uSec before returning high
For 9600 baud Tx time = 975 uSec
for 19200 Buad Tx time = 460 uSec
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 119
Posts: 10172
|
 |
« Reply #11 on: April 30, 2012, 10:13:40 pm » |
New byte times for 14400 baud: The Uno Tx pin is high is goes low for 625 uSec then return high(the previous value was in error) Perfect match (625.5us is the expected value). on incoming from PC the Rx is high and goes low for 725 uSec before returning high Corresponds to 12413.8 baud. Good news: The code on the Uno is correct. Bad news: The code on the ATmega16U2 has a bug.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #12 on: May 01, 2012, 11:25:23 am » |
what is the next step?
unrelated question: Is it possible to read/write a block (8 bits) of digital ports in one command?
Thanks for your help
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 90
Posts: 9414
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #13 on: May 01, 2012, 12:16:33 pm » |
unrelated question Yes it is called direct port manipulation - http://www.arduino.cc/en/Reference/PortManipulation -
|
|
|
|
|
Logged
|
|
|
|
|
|
|
|