arduino serial running @ 250bps

Hello forum people!

I wanted to know, is it possible to make arduino output serial data @ 250bps is it as simple as Serial.begin(250); ?

Thanks in advance! BR.

Should work. The documentation says it will do the normal speeds: 300, 1200, 2400... and "You can, however, specify other rates". I would fully expect 250 BPS to work.

So it would seem: http://arduino.cc/en/Serial/Begin

Well there is certainly some specific maximum and minimum baud rate value, depending on the clock frequency and the baud rate divider capacity. Just not sure what the two extremes baud rate values are for a 16Mhz clock rate.

Lefty

retrolefty: Well there is certainly some specific maximum and minimum baud rate value, depending on the clock frequency and the baud rate divider capacity. Just not sure what the two extremes baud rate values are for a 16Mhz clock rate.

The baud rate is 16Mbps / (16 * (UBRR0+1)) and UBRR0 is a 12-bit register (0-4095). That makes the minimum speed 244.14 bps.

To get 250 bps you'd use UBRR0 = 16 Mbps/(16 * 250 bps)-1 which is exactly equal to 4000.

johnwasser:

To get 250 bps you’d use UBRR0 = 16 Mbps/(16 * 250 bps)-1 which is exactly equal to 4000.

Well, to get picky, the register value would be 3999, which would result in a rate of exactly 250 bps if the Arduino clock is exactly 16 MHz.

But to answer the Original Poster’s question: For Arduino version 22, if your board is running with a 16 MHz clock, the HardwareSerial::begin() function will use “2X” UART mode for that setting, and I believe that Serial.begin(250) will not work since it would require a 13-bit number in ubrr0. In fact, it looks to me as if any settings below 489 will try to load the baud rate register with something larger than a 12-bit number.

I think a simple modification to HardwareSerial.cpp will the trick. With arduino-0022 I have verified that, with a CPU clock of 16 MHz, 300 baud settings do not work without modification.

Here’s my suggestion for a modified HardwareSerial::begin() function in that file:

void HardwareSerial::begin(long baud)
{
  uint16_t baud_setting;
  bool use_u2x = true;

#if F_CPU == 16000000UL
  // hardcoded exception for compatibility with the bootloader shipped
  // with the Duemilanove and previous boards and the firmware on the 8U2
  // on the Uno and Mega 2560.
  if (baud == 57600) {
    use_u2x = false;
  }
#endif
  
  // Beginning of modified code, suggested by davekw7x
  if (use_u2x) {
    *_ucsra = 1 << _u2x;
    baud_setting = (F_CPU / 4 / baud - 1) / 2;
    if (baud_setting > 0xfff) { // ubrr is a 12-bit register
      use_u2x = false;
    }
  } 
  if (!use_u2x) {
    *_ucsra = 0;
    baud_setting = (F_CPU / 8 / baud - 1) / 2;
  }
  // End of modified code

  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
  *_ubrrh = baud_setting >> 8;
  *_ubrrl = baud_setting;

  sbi(*_ucsrb, _rxen);
  sbi(*_ucsrb, _txen);
  sbi(*_ucsrb, _rxcie);
}

Verified (with minicom and with Arduino serial terminal) for common baud settings from 300 through 115200 with Arduino Uno and Duemilanove boards operating with F_CPU = 16000000. (See Footnote.)

I believe that it should work for 250 baud, but I have no way of testing just now.

Regards,

Dave

Footnote:
For me, “common” rates are the following: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, and 115200. Note, particularly that the Arduino Serial Monitor 14400 and 28800 settings are not usable on my Linux system, and, in fact if I select either of these two, Bad Things happen that make me have to manually edit the serial.debug.rate entry in my .arduino/preferences.txt file to be able to use the Arduino IDE to do any more uploads.

davekw7x: For Arduino version 22, if your board is running with a 16 MHz clock, the HardwareSerial::begin() function will use "2X" UART mode for that setting, and I believe that Serial.begin(250) will not work since it would require a 13-bit number in ubrr0. In fact, it looks to me as if any settings below 489 will try to load the baud rate register with something larger than a 12-bit number.

So that means the documentation is wrong when it says you can do 300 baud. Great.

So that means the documentation is wrong when it says you can do 300 baud. Great.

I think it's a historical thing where along the lines of newer arduino board releases the bootloader was changed to set and utilize the X2 baud rate thingee. Certainly there was a time where 300 baud did work. The arduino platform is mature enough now that there are lots of legacy issues in core libraries and of course the site's documentation.

Lefty

Well there is certainly some specific maximum and minimum baud rate value

(just replied this same on another thread today :) High End: I used 230.400 and 345.600 baud several times and tested 500.000 once with no failures. On the PC side I used putty.exe to handle this speed. See - http://arduino.cc/forum/index.php/topic,61381.0.html -

Q: Where do you need 250 bps for? Furthermore: these speeds can be done in software too - adding an entry to the NewSoftSerial class is not too difficult