RS232: To parity or not to parity?
serial-port
Solution
Suggest calculating and appending a CRC instead of checksum. 16-bit may meet your needs - I'd use 32-bit. A 16-bit with random noise will fail 1 in 64k. 32-bit 1 in 4G.
Checksum, though easy to calculate suffers from noise burst that are interpreted as a 0 - not that uncommon as far as serial errors go.
The overhead calculation is a bit off. 1 start + 8 data + 1 stop bit = 10 vs. 10 + parity = 11.
Parity is not worth it IMO. Does not detect much beyond what the framing error (wrong stop bit) provides. Does not provide message integrity.
Problem
I'm starting to write code for a device that'll stream data in and out in full duplex mode, so I'll be using hardware handshaking and setting a break condition when something goes wrong. But when it comes to error detection it's less clear what the best way to go is. RS232 has built-in parity checking that I could use. As I understand it, if I use 8 data bits, one parity bit and one stop bit then the packet on the wire will be 10 bits. This means that for every 1024 bytes I send, I'm also sending 128 bytes of validation information interleaved with it. Since parity is a 50/50 thing for each byte, it's not too unlikely that a short burst of noise lasting less than one byte will cause corruption that's still consistent with the parity bit. So it doesn't seem a reliable test. If I use a checksum at the end of each 1024 bytes, which is still only 80ms at 115200 baud, my validation overhead goes down from 12% to less than 1%, even if I use a 64 bit checksum. And it's harder to miss corruption. Is parity simply a technology that was useful in the days of sub 100 baud connections and is long since obsolete, and I should go with a block checksum, or am I missing something?