Go Down

Topic: Mega Baud rate Error (Read 2 times) previous topic - next topic

T3bear

Apr 29, 2012, 09:32 pm Last Edit: Apr 29, 2012, 09:36 pm by T3bear Reason: 1
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);
    }
}

Coding Badly

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


How did you arrive at that conclusion?

T3bear

I was watching the input and output pulses on a scope.  The pulse width seems to right and consistent for 9600 and 19200 baud.

T3bear

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

robtillaart

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?

Rob Tillaart

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

T3bear

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

T3bear

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.

Coding Badly


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: [Select]
void loop( void )
{
  Serial.write( (byte)(0x00) );
  delay( 1000 );
}

T3bear

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

Coding Badly


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?

T3bear

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

Coding Badly


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.

T3bear

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


robtillaart

Quote
unrelated question

Yes it is called direct port manipulation - http://www.arduino.cc/en/Reference/PortManipulation -
Rob Tillaart

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

Coding Badly

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.

Go Up