Raspberry Pi 9-Bit Serial

There isn’t any easy way to use 9-Bit RS-485 mode ascii in linux. This mostly comed down to the fact that the posix standard only specifies even or odd parity not mark or space.  There are a few different ways

  • Extending the pigpio gpioWaveAddSerial() function for 9-bit – This sounds a bit like glorified bit-banging. I’ve heard that it uses quite a lot of cpu time and there isn’t any satisfactory way to read data. Still it looks like some people are making great progress.
  • Simulating mark or space parity by setting even or odd parity according to the byte being sent.  This has some appeal to me because all the hard work can be done in software.  Provided that the parity settings can be changed without causing any significant sending delay of course. Apparently it works. I might give it a try later.
  • Using an external UART that’s actually capable of doing RS-485 out of the box -This is what I’ve done.

The UART I found was the SC16IS750. It will connect to the Raspberry Pi’s I2C or SPI bus, and will do just about any serial mode you can think of over a huge range of speeds. Spark fun also sell one on a handy breakout board.

IMG_0317
SC16IS750 breakout board from SparkFun – notice the extra wire required to use the IRQ pin.

The datasheet is huge but driving it mostly boils down to reading and writing registers via the I2C or SPI bus.  The only thing that wasn’t clearly explained was that you have to let the output buffers drain before switching between writing 9-bit address and data bytes.

I’ve written a python class which makes it easy to read and write messages. The proof is here.  The code is finally in github here https://github.com/mikeyg123/pi-alarm

IMG_0320

2 thoughts on “Raspberry Pi 9-Bit Serial”

Leave a comment