Go Down

Topic: 300 Baud for Mega 2560 (Read 912 times) previous topic - next topic

inspectorCleve

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

xolroc

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

inspectorCleve

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  =(

Tom Carpenter

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

Code: [Select]
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.
~Tom~

inspectorCleve

This sounds great!!! 8)
I will try this and give my feedback asap
Thanks
Cheers Nils

inspectorCleve

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  :~
If not I will follow up

Thanks

Tom Carpenter

This works for me:
Code: [Select]

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

Go Up