Pages: [1]   Go Down
Author Topic: 300 Baud for Mega 2560  (Read 828 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
when looping back my via

if (Serial.available())
{
    int inByte = Serial.read();
    Serial.write(inByte);
}

It only returns rubbish - when using 300 Baud
With every other Baud rate it works.

I have read https://github.com/arduino/Arduino/commit/db64d2fc323219c3487947aa28bee07385c96a67

Do I get that right, that the Ports 1 and 2 will work with 300 baud?

How can I get my USB run with 300 Baud?

Thanks & regards
Nils
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 135
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The real question here is "Why do you want to use 300 baud"?  For serial communication, that's ridiculously slow!
Logged

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

Indeed this is very slow - I would appreciate if my power meters I would like to communicate with would be faster. But there is no chance to speed those devices up  smiley-cry
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In arduino, set it to 600BAUD, then turn of double speed. (the baud rate will then half)

Code:
Serial1.begin(600);
UCSR1A &= ~(1<<U2X1);


Basically, the BAUD rate generator can only store 12bit values. By default Arduino turns on double speed, which means that the generator value is:

UBRRn = fcpu/(8*BAUD) -1
For 300baud, this is
UBRRn = 16000000/(8*300) -1 = 6665.
This is a 13bit number, so cannot be stored. (If you try and save it, it will be truncated to 2569 = 6250BAUD, hence you have a problem)

By disabling the double speed bit, the calculation becomes:
UBRRn = fcpu/(16*BAUD) -1
For 300baud, this is
UBRRn = 16000000/(16*300) -1 = 3332.
This nicely fits into 12 bits, so you will be able to easily generate 300 BAUD.
Logged

~Tom~

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

This sounds great!!! smiley-cool
I will try this and give my feedback asap
Thanks
Cheers Nils
Logged

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

No - this Does not work  smiley-sleep
But I will follow up on this later - perhaps I have to equip with another Peace of hardware which is faster  smiley-confuse
If not I will follow up

Thanks
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 78
Posts: 1719
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This works for me:
Code:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(600);
  UCSR0A &= ~(1<<U2X0);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("HI, I'm 300BAUD");
  delay(1000);
}

I see now that you wanted to send it through the USB not throught UART1. The code above communicates fine with the computer (through UART0 and hence the USB port) with x-ctu (terminal) set at 300 baud.
Logged

~Tom~

Pages: [1]   Go Up
Jump to: