Pages: [1] 2   Go Down
Author Topic: Mega Baud rate Error  (Read 2636 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

on 14400 the pulse width varies from bit to bit (from 50 to 100 uSec)

How did you arrive at that conclusion?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using IDE 1.0, will give another a try.  Thanks
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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...

Code:
void loop( void )
{
  Serial.write( (byte)(0x00) );
  delay( 1000 );
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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 Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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).

Quote
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 Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
unrelated question
Yes it is called direct port manipulation - http://www.arduino.cc/en/Reference/PortManipulation -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 199
Posts: 12768
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

what is the next step?

If you want it fixed quickly, you will probably have to do it yourself (or hire someone).  I believe the problem is with the SERIAL_2X_UBBRVAL macro called here...
https://github.com/arduino/Arduino/blob/master/hardware/arduino/firmwares/arduino-usbserial/Arduino-usbserial.c#L209

If you want the problem fixed in future boards, I suggest reading how others have sought redress..
http://arduino.cc/forum/index.php/topic,64256.msg479323.html#msg479323

At a minimum, please report the problem here (include a link to this topic)...
http://code.google.com/p/arduino/issues/list

If you remain unsure how to proceed, report back.  Maybe someone else can offer better advice then I've given.
Logged

Pages: [1] 2   Go Up
Jump to: