user21214: I want send and receive a 9 bit async-serial protocol with 4800 baud on my Arduino Uno, i have read on the specification from the ATmega328P that the uart can do that.
My aim is that when my Uart receive the 9th bit as a 1 he must throw a interrupt. On this interrupt i can recognize that this byte was an adress byte.
When he receive a zero he sould do nothing spezial, only transmit it as hex-byte over usb to the pc.
My Problem now, i can´t initialize the Uart right because the command Serial.begin(4800, config) is not enough, i must throw the interrupt and translate the data to hex-bytes.
My Question can i modify the Serial.begin() source code respectively where can i find the source code for the Serial.begin function?
When there is no possibility to change the code has someone a other option for me to send and receive the 9 bit protocol with an Arduino Uno?

user186: It sounds like you want some device with a 9-bit protocol to send data to an Arduino, and then the Arduino to forward that data (perhaps in a slightly different format) to a PC.
People who want to connect their Arduino to two serial devices at the same time (and the PC counts as one) generally either:
Change the hardware to accept multiple serial devices
While the Arduino Uno has only one hardware serial port, the following (and probably many others) have 2 or more hardware serial ports:

Arduino Mega 2560 (USB and 3 other hardware serial ports)
Arduino Leonardo (USB and 1 other hardware serial port)
Teensy LC (USB and 3 other hardware serial ports) ("serial 9-bit on the t3")

("Sending and Receiving 9-bit Frames with Arduino" uses the hardware approach).
Change the software to accept multiple serial devices
In principle, it's possible to tweak SoftwareSerial to handle 9-bit data.
Several people have talked about it

"9bit SoftwareSerial library modification"
"Altering New Soft Serial NSS for 9 bit- cans of open source worms"


user41773: The Max3140 is a very capable USART with built-in full/half-duplex RS-485 drivers that interfaces to a uController via SPI. They are a bit pricey and you would have to make a board, solder, etc.. 
Another solution would be to dedicate a simple and inexpensive minimal Arduino-compliant board (like a Pro-Mini) to interface with the "main" Arduino via I2C or SPI, and program the Pro-Mini for 9-bit addressing mode and add the RS-485 driver. Pro-Mini or Nano clones are dirt cheap, but it is not even that expensive to use an authentic Arduino product and support their great contributions ;-).

user7508: If you want to set the UART to 9-bit mode, you will have to set the
UCSZ02 bit of the _ucsrb register to 1 in
HardwareSerial::begin().
For example:
void HardwareSerial::begin(unsigned long baud, byte config)
{
  // Mostly unchanged... but by the end:
  sbi(*_ucsrb, RXCIE0);
  cbi(*_ucsrb, UDRIE0);
  sbi(*_ucsrb, UCSZ02);  // set 9-bit data mode
}

Notice that you do not need to modify the Arduino core library for this:
you could set that bit in your setup(), right after calling
Serial.begin().
Then, in the HardwareSerial::_rx_complete_irq() interrupt
handler,
you will have to read the 9th bit as the RXB80 bit in UCSR0B, before
reading the low byte from _udr (emphasis in the datasheet). For
example, you could replace the line unsigned char c = *_udr; by:
bool is_address = UCSR0B & _BV(RXB80);  // read 9th bit first
unsigned char c = *_udr;                // then the other bits
if (is_address) {
  do_something_with_address(c);
  return;
}

where do_something_with_address() is the stuff you wanted to do in
another interrupt (no need for that, you are already in interrupt
context).
It is worth noting that, with an Arduino Uno, you will not be able to do
all this while sending data to the PC. This is because the communication
with the PC uses the only UART of the ATmega328P.

21214: <p>I want send and receive a 9 bit async-serial protocol with 4800 baud on my Arduino Uno, i have read on the specification from the ATmega328P that the uart can do that.
My aim is that when my Uart receive the 9th bit as a 1 he must throw a interrupt. On this interrupt i can recognize that this byte was an adress byte.
When he receive a zero he sould do nothing spezial, only transmit it as hex-byte over usb to the pc.</p>

<p>My Problem now, i can´t initialize the Uart right because the command Serial.begin(4800, config) is not enough, i must throw the interrupt and translate the data to hex-bytes.
My Question can i modify the Serial.begin() source code respectively where can i find the source code for the Serial.begin function?</p>

<p>When there is no possibility to change the code has someone a other option for me to send and receive the 9 bit protocol with an Arduino Uno?</p>
 186: <p>It sounds like you want some device with a 9-bit protocol to send data to an Arduino, and then the Arduino to forward that data (perhaps in a slightly different format) to a PC.</p>

<p>People who want to connect their Arduino to two serial devices at the same time (and the PC counts as one) generally either:</p>

<h2>Change the hardware to accept multiple serial devices</h2>

<p>While the Arduino Uno has only one hardware serial port, the following (and probably many others) have 2 or more hardware serial ports:</p>

<ul>
<li><a href="https://www.arduino.cc/en/Main/ArduinoBoardMega2560" rel="nofollow">Arduino Mega 2560</a> (USB and 3 other hardware serial ports)</li>
<li><a href="https://www.arduino.cc/en/Main/ArduinoBoardLeonardo" rel="nofollow">Arduino Leonardo</a> (USB and 1 other hardware serial port)</li>
<li><a href="https://www.pjrc.com/teensy/teensyLC.html" rel="nofollow">Teensy LC</a> (USB and 3 other hardware serial ports) (<a href="https://forum.pjrc.com/threads/23873-serial-9-bit-on-the-t3" rel="nofollow">"serial 9-bit on the t3"</a>)</li>
</ul>

<p>(<a href="http://blog.bouni.de/blog/2014/10/07/sending-and-receiving-9-bit-frames-with-arduino/" rel="nofollow">"Sending and Receiving 9-bit Frames with Arduino"</a> uses the hardware approach).</p>

<h2>Change the software to accept multiple serial devices</h2>

<p>In principle, it's possible to tweak SoftwareSerial to handle 9-bit data.
Several people have talked about it</p>

<ul>
<li><a href="http://forum.arduino.cc/index.php?topic=345147.0" rel="nofollow">"9bit SoftwareSerial library modification"</a></li>
<li><a href="http://citizengadget.com/post/22556427458/altering-new-soft-serial-nss-for-9-bit-cans-of" rel="nofollow">"Altering New Soft Serial NSS for 9 bit- cans of open source worms"</a></li>
</ul>
 41773: <p>The Max3140 is a very capable USART with built-in full/half-duplex RS-485 drivers that interfaces to a uController via SPI. They are a bit pricey and you would have to make a board, solder, etc.. </p>

<p>Another solution would be to dedicate a simple and inexpensive minimal Arduino-compliant board (like a Pro-Mini) to interface with the "main" Arduino via I2C or SPI, and program the Pro-Mini for 9-bit addressing mode and add the RS-485 driver. Pro-Mini or Nano clones are dirt cheap, but it is not even that expensive to use an authentic Arduino product and support their great contributions ;-).</p>
 7508: <p>If you want to set the UART to 9-bit mode, you will have to set the
UCSZ02 bit of the <code>_ucsrb</code> register to 1 in
<a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp#L103" rel="noreferrer"><code>HardwareSerial::begin()</code></a>.
For example:</p>



<pre class="lang-c++ prettyprint-override"><code>void HardwareSerial::begin(unsigned long baud, byte config)
{
  // Mostly unchanged... but by the end:
  sbi(*_ucsrb, RXCIE0);
  cbi(*_ucsrb, UDRIE0);
  sbi(*_ucsrb, UCSZ02);  // set 9-bit data mode
}
</code></pre>

<p>Notice that you do not need to modify the Arduino core library for this:
you could set that bit in your <code>setup()</code>, right after calling
<code>Serial.begin()</code>.</p>

<p>Then, in the <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/cores/arduino/HardwareSerial_private.h#L101" rel="noreferrer"><code>HardwareSerial::_rx_complete_irq()</code> interrupt
handler</a>,
you will have to read the 9th bit as the RXB80 bit in UCSR0B, <strong>before</strong>
reading the low byte from <code>_udr</code> (emphasis in the datasheet). For
example, you could replace the line <code>unsigned char c = *_udr;</code> by:</p>

<pre class="lang-c++ prettyprint-override"><code>bool is_address = UCSR0B &amp; _BV(RXB80);  // read 9th bit first
unsigned char c = *_udr;                // then the other bits
if (is_address) {
  do_something_with_address(c);
  return;
}
</code></pre>

<p>where <code>do_something_with_address()</code> is the stuff you wanted to do in
another interrupt (no need for that, you are already in interrupt
context).</p>

<p>It is worth noting that, with an Arduino Uno, you will not be able to do
all this while sending data to the PC. This is because the communication
with the PC uses the only UART of the ATmega328P.</p>
