I need to use serial port to communicate with a device. It requires 8 data bit Odd parity check and 2 stop bits.
My question is: Is there any pre-processing required to the data that I need to send through serial port with 8O2 method or the hardware will take care of it?
What if the received message has an error and parity check fails? Do I need to write a software program to check parity of the received data or the micro-controller hardware will handles the parity check in the background? What happens to the received message with error in parity check? Will serial.available() be zero or some other value?
I really don’t know much about serial communication. Thanks for your help in advance!
The arduino serial library code allows one to set up the serial link using options including even or odd parity generation.
Serial.begin(9600, SERIAL_8O2); // this should configure the AVR for what you asked for, speed adjusted of course
However while that will allow you to send the data with proper parity being sent automatically in hardware, the present serial library does not include any receiver parity error detection function so you have to write your own error detection function if you wish to detect incoming characters that may have bad parity. The AVR serial hardware does support detecting parity errors, but the arduino serial library code does not utilize it (yet).
Normally one just configures the serial to be compatible with what you are wiring it to and just assume you will never receive a bad character from the device, not the most reliable method but that’s how the vast majority the serial links operate, bad data just passes through as if it was not bad. For more critical serial links one often turns to ‘packeting’ the serial data appended with CRC error detection characters and testing for valid CRC on all received packets.