Serial parity bit - Page 1
Forum section: electronics / general

author: Circlotron
author_rank: Super Contributor
timestamp: September 30, 2015, 10:10:06 pm
content: Hi all. Just writing some bit banging software in assembly for a HC08. Getting confused about the parity bit. Say we are running even parity. Does that mean that if there are an even number of 1's in a given frame then the parity bit is set to show that there is an even number, or that if there is an odd number then the parity bit is set to make it up to an even number?Also, is the start bit included in the bit count? What about the stop bit?Also also, assuming a 1 is low, the start bit is low and the stop bit is high?Is the parity bit low or high?Does the parity bit come just before the stop bit?Spent lots of time going around in circles lately

author: djacobow
author_rank: Super Contributor
timestamp: September 30, 2015, 10:21:16 pm
content: From wikipedia:https://en.wikipedia.org/wiki/Serial_port#Parity"Parity is a method of detecting errors in transmission. When parity is used with a serial port, an extra data bit is sent with each data character, arranged so that the number of 1 bits in each character, including the parity bit, is always odd or always even. If a byte is received with the wrong number of 1s, then it must have been corrupted. However, an even number of errors can pass the parity check."So the parity bit is set to one if ODD parity and the number of ones in the word transmitted is even. The results in an odd number of ones, total.If the parity were even and the number of ones in the word was even, then the bit would be clear, keeping it even.Personally, I say N,8,1 or go home. :-)

author: suicidaleggroll
author_rank: Super Contributor
timestamp: September 30, 2015, 10:21:32 pm
content: This goes through it at a pretty low level:http://www.unm.edu/~zbaker/ece238/slides/UART.pdfThis is also a case when grabbing a computer with a USB to UART adapter and a logic analyzer is immensely helpful. Configure hyperterminal/putty/kermit/minicom with your settings, including parity, then send a few characters out on the UART and capture them with a LA to see what it sent.

author: Circlotron
author_rank: Super Contributor
timestamp: October 01, 2015, 01:48:53 am
content: Quote from: djacobow on September 30, 2015, 10:21:16 pmI am building a board that communicates with an automatic sliding door so I have to fit in with what it wants - 1200,E,8,1 so far as I can determine.What I understand so far is this:Data line is normally +12VStart bit goes to 0V for 833uS (logic 1)8 data bits - logic 1 = 0VIf odd number of zeros in byte then parity bit goes low (logic 1) to make even number (= even parity)Stop bit goes +12V (logic 0)Is each of these points correct?

author: Circlotron
author_rank: Super Contributor
timestamp: October 01, 2015, 01:58:05 am
content: This pic shows start bit as 1 and stop bit as 0http://www.csurambox.com/documents/report/images/report_img_12.jpgAnd this pic shows start bit as 0 and stop bit as 1http://www.ermicro.com/blog/wp-content/uploads/2008/12/rs232_01.jpgAny wonder I am confused.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: October 01, 2015, 02:00:01 am
content: Quote from: Circlotron on October 01, 2015, 01:58:05 amTTL UART and RS232 polarity is swapped. UART idles high, RS232 idles low.http://www.artekit.eu/ak-3232-usage-guide/

author: helius
author_rank: Super Contributor
timestamp: October 01, 2015, 05:45:39 am
content: Quote from: Circlotron on October 01, 2015, 01:48:53 amRS-232-C swings both ways around 0 V. 0 V is an invalid state.The descriptions online are confusing because they tend to use the wrong terms. In serial comms, there is not "high and low", the line states are referred to as mark and space. Originally "mark" and "space" referred to the holes in a paper tape attached to a teletype. It's important to get the right concepts, because serial communications can use different voltage levels and electrical signals, while keeping the same logical format. You could think of it as "Layer 1/Layer 0" in the OSI model: the format of marks and spaces is Layer 1, but the interpretation of those marks as voltages is at a lower level that could take multiple forms. RS-232-C, EIA-422, EIA-423, EIA-485, and current loop have the same marks but are electrically different. When you use "TTL UART", the voltage levels are different, but the marks and timing are still the same. That's why you can convert between TTL and RS-232 levels with ordinary transistors.Data words are sent with logical 1 as a mark, 0 as a space. The start bit is always a space, and the stop bit(s) are always marks. In between words the idle state is mark. Each word starts with a start bit, then the bits of the data LSB first, (optional parity bit), and then 1 or 2 stop bits. The number of stop bits is not that important, because asynchronous serial comms idle in the same state (marking). The stop bits act as a minimum idle time between words. So if you send 2 stop bits, and the receiver expects 1, it will still understand.Parity is sent with different modes, either even, odd, mark, space, or no parity. Mark or space parity always sends mark or space in the parity bit. Even (odd) parity sends a bit, so that the sum of the number of spaces in both the data and parity is even (odd). This means that a 7-bit word equal to 0x0 gets a different even parity than an 8-bit word with the same value. In practice the most common format is 8-N-1, so this isn't noticed.The voltage levels assigned to a mark and space are a different issue and can be examined entirely separately from the above.In RS-232-C, a mark is transmitted as -12 V and received from -2 to -25 V. A space is transmitted as +12 V and received from +2 to +25 V.In EIA-423, a mark is transmitted as -5 V and received from -4 to -6 V. A space is transmitted as +5 V and received from +4 to +6 V.In EIA-422, signals are balanced between two wires, with the common-mode voltage ignored, and the differential voltage (noninverted minus inverted) being transmitted as -5 V for a mark, +5 V for a space, and received from -.200 V to -12 V, and +.200 V to +12 V respectively.TTL transmits a mark as Vcc and a space as Gnd. Converting between these different electrical standards just uses transceivers that know nothing about bits or baud rates. On the other side, when you program software, the only thing that matters is the marks and spaces.Edit: mind your +s and -s

author: Circlotron
author_rank: Super Contributor
timestamp: October 01, 2015, 12:19:51 pm
content: Righteo, got it all sorted out now! Thanks for your help everybody.