Serial Rx with odd baud rates

(How) Is it possible with the Arduino to receive serial communication at "unusual" speeds?

Also, what is the lowest speed possible?

#Edit:
I am only interested in odd baud rates at low speeds (<300 baud). Therefore, I assume softwareserial could be used instead of hardware serial.
Are hardware serial and software serial adjusted the same way?

For HardwareSerial you need to study the Atmel datasheet. It includes a table of possible baud rates.

I don't know the innards of the SoftwareSerial library - but the source code comes with your Arduino IDE.

You may be interested in my Yet Another Software Serial which I wrote to expose the workings (as well as to use Timer2 so it does not conflict with the Servo library). I haven't tried, but I suspect you could modify it for low baud rates.

...R

From the ATmega328P datasheet:

fosc is the frequency of the system clock oscillator, typically 16,000,000 Hz.
UBRRn is a 12-bit configuration register value (0-4095)

BAUD = fosc / (16 * (UBRRn+1))

Maximum: 16,000,000 / (161) = 1,000,000 baud
Minimum: 16,000,000 / (16
4096) = 244.14 baud

There is also double-speed mode where the max is 2,000,000 baud and the min is 488.3 baud.

Of course if you use an 8 MHz system clock everything is half the normal speed.

You can also use the CLKPR (Clock Prescale Register) to slow everything down by a factor of 2, 4, 8, 16, 32, 64, 128, or 256. Note that the microsecond and millisecond times will slow down as well. If you set the clock prescale to 128 then you 16 MHz system clock becomes 62.5 KHz and your minimum baud rate becomes 0.95 baud. I hope that is low enough for you.

1 Like

Note that not all serial devices allow such a level of control over the baud rate - in some cases, only a subset of the "standard" baud rates is supported.

With "bit bang" serial software, you can have any imaginable baud rate. Very simple, too.

Transmit routine:

void sputchar( uint8_t c )
{
  c = ~c;
  STX_PORT &= ~(1<<STX_BIT);            // start bit
  for( uint8_t i = 10; i; i-- ){        // 10 bits
    _delay_us( 1e6 / BAUD );            // bit duration
    if( c & 1 )
      STX_PORT &= ~(1<<STX_BIT);        // data bit 0
    else
      STX_PORT |= 1<<STX_BIT;           // data bit 1 or stop bit
    c >>= 1;
  }
}

From the formula in the datasheet (also johnwasser's post) I would need a System Clock Prescaler of at least 8 to be able to receive messages at 45 baud, assuming a 16 MHz oscillator, though the microcontroller would run only at 2 MHz then.
That is too slow (while performing some other tasks in the background), so the software serial seems a better solution.

I am only interested in the receiving of low speed messages, not transmitting them.
So I will take a look at the "Yet another Software Serial" code.