Maybe a simple question, but I can't seem to find it.

Parity check is simple error detection.

But is in done in hardware on the arduino and is the data discarded before i can read it from software?

The reason I ask this quote from Thomas

1 Command bit, set on the first character of each datagram. Reflected in the parity bit of most UARTs. Not compatible with NMEA0183 but well suited for the multiprocessor communications mode of 8051-family microcontrollers (bit SM2 in SCON set).

From http://www.thomasknauf.de/rap/seatalk1.htm#Dat which might have confused me. So I guess this is not an option ... after the feedback from users.

So i need to read the 9 bit and since the hardware support it. The Arduino team won't implement it, since it has a bigger overhead and it's really not used anymore ... I agree ... but the SeaTalk bus uses it ... so I'm stuck here.

But after more seaching I found this GitHub repo: https://github.com/rob42/FreeboardPLC_v1_2 which have made changes to the HardwareSerial.h and HardwareSerial.cpp but only for version 1.5.7

Think I will go for this version unless someone have done the mods to 1.6.x ... have searched the web. Later I will try to see if I can get it to work with 1.6.x ... but since this is all new. I'm taking small steps.

  • 1
    I am not familiar with atMega, but on the chips I know (PIC, Cortex) when a parity error occurs, the parity error flag is set and the data byte is discarded, so you can't use it to fake 9 bit data. But Some UARTs doe have a 9-bit mode. You should check the data sheet of the chip (has nothing to do with arduino). – Wouter van Ooijen Aug 10 '15 at 21:54
  • There are two partial queries here - one is asking about parity check on (I assume) the Atmega2560. The other is asking whether you can transmit 9-bit data on the same chip. Please help by clarifying which of the two is your actual question. – Stefan Dzisiewski-Smith Aug 10 '15 at 22:45
  • @wouter Thank ... I read more and got a bit more knowledge about the subject. – Syska Aug 11 '15 at 8:23
  • @stefan I have cleared up the question and also the part why I was looking into the Parity part ... which I guess is not the right way to go. – Syska Aug 11 '15 at 8:23

This came up a while back on the Arduino Forum - talking about Asynchronous SeaTalk.

I made a modified version of HardwareSerial which can be downloaded from http://gammon.com.au/Arduino/HardwareSerial9bit.zip

Changes are:

  • The internal buffers have been changed from 8-bit characters to 16-bit characters (to hold the 9th bit). Thus the buffers double in size.

  • There is a new argument to the Serial.begin() function, which is a boolean, whether or not you want 9-bit mode. It defaults to false.

  • There is a new function Serial.write9bit (). This takes an unsigned int argument, letting you supply a character with the 9th bit set. I didn't want to change the existing write function because it is used in the Print class.

  • The read function, which already returns an int, now will return the 9th bit where required.

Example code:

void setup ()
 Serial.begin (115200);  // debugging prints
 Serial1.begin (115200, true);  // 9 bit mode
 Serial2.begin (115200, true);  // 9 bit mode
 Serial.println ("--- starting ---");
}  // end of setup

int i;

void loop ()

 Serial1.write9bit (i++);  // send another byte

 // display incoming on Serial2
 if (Serial2.available ())
   Serial.println ((int) Serial2.read (), HEX);

 // check if we have sent all possible characters
 if (i >= 0x200)
   delay (100);
   while (Serial2.available ())
     Serial.println ((int) Serial2.read (), HEX);
   delay (5000);
   i = 0;
   }  // end of sent 512 bytes
}  // end of loop

As Ignacio Vazquez-Abrams said, the hardware supports this 9-bit mode natively, it just takes a bit of fiddling around to make it work.

Because of the way that hardware serial is integrated into the IDE it is, unfortunately, necessary to find your existing files:

  • HardwareSerial.cpp
  • HardwareSerial.h

... and replace them with the ones in the download.

Note that this is for version 1.0.1 of the IDE. No guarantees are given that this will work with other versions. This was written a while back, I'm not sure what changes have been made to HardwareSerial in the meantime.

The actual changes are here: http://gammon.com.au/Arduino/hardwareSerial_diffs.txt

You could use those to guide your implementation on more recent versions, if the file download does not work "as is".


AVR devices with a hardware USART have a real 9-bit mode; there is no need to "fake" it.

But to answer your question, it is done in hardware; the appropriate USART Parity Error bit is set and while the datasheet is vague about it, it is implied that the data is stored in the receive buffer.

  • Thanks. That cleared up some of my confusion and also added more. Have updated the question with more information about my original issue since the parity check is not the way to go. – Syska Aug 11 '15 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.