Jakeyboy
Posts: 4
Joined: Sat Jul 19, 2014 8:14 pm

9-bit Serial by way of parity bit

Sat Jul 19, 2014 8:29 pm

I am trying to implement a 9-bit serial @ 9600 NRZ with start and stop bits but no parity. Based on the information I can find the UART in the RPI does not support 9-bits natively...

http://www.raspberrypi.org/wp-content/u ... herals.pdf @ page 175

However since I don't need to make use of the parity bit I would like to use this as the 9th bit.

I first attempted this within PI4J but it does not currently have the ability to control the parity bit. I am now looking into using RXTX which seems to make this possible but any opinion on the topic would be much appreciated.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: 9-bit Serial by way of parity bit

Sat Jul 19, 2014 9:04 pm

I would have thought that the parity bit is based on the value of the byte you are sending?

Jakeyboy
Posts: 4
Joined: Sat Jul 19, 2014 8:14 pm

Re: 9-bit Serial by way of parity bit

Sat Jul 19, 2014 9:19 pm

Generally the parity bit is permanently set or calculated based on the normal 8 bits as apart of error checking I believe. I am saying I want to manually control it and use it as 9th bit of information.

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: 9-bit Serial by way of parity bit

Sat Jul 19, 2014 10:14 pm

I am not familiar with Java, but I assume you are running it on Linux. Linux (indeed, POSIX) does not support 9 bit serial data on any hardware platform, so this is not a Pi-specific problem. Linux does support 8 bits plus parity.

You could look at the low 8 bits of each nonet you wish to send, and then decide whether to set odd or even parity so that the correct 9th bit will be added. (Some drivers support mark and space parity, which would make the decision very slightly easier. Last time I checked, the Pi did not, and such options are unlikely to be accessible in minority languages anyway. Just use a parity lookup table or some shifts and xors.)

I suspect you would need to flush the output after each byte to ensure the hardware has finished adding the correct parity bit before it is told what to use for the next byte. Not very efficient, but at 9600 baud it may be practical.

9 bit input is even messier. Set a fixed parity, even or odd, and enable the termios option PARMRK. When a byte plus your selected parity is received you read just that byte. For a byte with incorrect parity you read 0xFF 0x00 BYTE. (For a byte of 0xFF with correct parity, you read 0xFF 0xFF.) From this you can reconstruct the received nonet.

josefm
Posts: 1
Joined: Sun Dec 21, 2014 12:23 pm

Re: 9-bit Serial by way of parity bit

Sun Dec 21, 2014 12:33 pm

May I join the discussion?
I have a similar problem:
I want to use Multi Processor Communication Mode on an AVR ATmega microcontroller and it requires a ninth bit set to have the microcontroller detect the frame as being an address frame and data frames will have the ninth bit clear.
I had hoped to use the RasPi as the master and a number of ATmegas as slaves and then wake up only one of the slaves using this mechanism.
I have learned that MARK parity can be achieved by setting the CMSPAR bit and EVEN/ODD parity in the termios data structure.
However, trying this with minicom (Ctrl-A, P, then selecting 8 data bits and MARK or SPACE parity) caused only 7 data bits to be sent (I tried sending a U character which has ASCII code 0x55, i.e. alternating 0 and 1 bits) and recordied it on a logica analyzer.
Is 8M1 (or 8S1) not possible on RasPi?

johndough
Posts: 254
Joined: Sun Jan 13, 2013 2:00 pm

Re: 9-bit Serial by way of parity bit

Mon Dec 22, 2014 12:12 pm

Hi

I know nothing about anything, however I had a look around and found...

http://digital.ni.com/public.nsf/allkb/ ... 990057F919

a snippet...
1. Use the parity bit as a 9th data bit:

Transmission:

You will need to set the port up for 8 data bits.
To add a ninth bit to your transmission, you will need to explicitly set the parity bit to Mark or Space for every byte that is transmitted. Mark is a high parity bit (1), and Space is a low parity bit (0).

For example, if you need to transmit binary 000100010, you would transmit hex 0x88 and set the parity to Space. If you needed to transmit binary 000100011 instead, you would still transmit hex 0x88 but set the parity to Mark. Note that when shown in binary the least significant bit is the leftmost bit, as the least significant bit is sent first in serial transmission.

Reception:

Set the port up for 8 data bits with parity checking enabled, set as either Space or Mark.
Read one byte at a time.
If you get any parity errors you know that the 9th bit is the opposite of what you set.
Append the appropriate bit.
############################

http://www.ti.com/lit/ds/symlink/sn74f280b.pdf

Struck me to consider "could the logic gates be simulated in software" and give an 8 bit transmittable answer, reversible at the receiver end?
logic gate.PNG
logic gate.PNG (43.63 KiB) Viewed 6970 times

User avatar
joan
Posts: 14960
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: 9-bit Serial by way of parity bit

Mon Dec 22, 2014 12:25 pm

pigpio allows for the sending of serial data with 9-bit word length. E.g. gpioWaveAddSerial.

I'm in the process of updating the software to allow for the reception of 9-bit data.

edo1
Posts: 169
Joined: Sun Jun 15, 2014 3:33 pm
Location: Russia

Re: 9-bit Serial by way of parity bit

Fri Mar 04, 2016 10:55 am

Jakeyboy wrote:Based on the information I can find the UART in the RPI does not support 9-bits natively...
It does indeed.

You could find kernel patch here:
http://marc.info/?l=linux-serial&m=145706834101241&w=2

nadgetastic
Posts: 9
Joined: Mon May 25, 2015 9:17 pm

Re: 9-bit Serial by way of parity bit

Thu Mar 31, 2016 6:10 pm

Another tip - don't go near the nasty RxTxComm library - instead, take a look at using jSerialComm. This should give you everything you need along with embedded native ports for Pi in both hard and soft float variants.
I'm getting vert positive results with the Modbus port here https://github.com/steveohara/j2mod

Return to “Java”