1

How can I send something more than 8 bits over UART? Any python libraries?

2

3 Answers 3

2

Usually you keep sending more bytes to transmit the full stream if information one would like to send. I.e. you need to send 1024 bit, so you send 128 bytes. Any odd number of bits can be compensated for using padding bits, i.e. zeros that you fill in at the sender and throw away at the receiver.

If you're asking about 9 bit transfer (9 bits transmitted per byte), see here: True 9-bit serial port data? where I take it that the pigpiod library is able to do 9 bit transfer with any port in a software UART mode, with limited baudrate of up to 19.2k though. The hardware UART of the Pi, as Milliways' answer suggests seems to be capable of 8 bit only.

1

The in-build UARTs on the Pi support a maximum of 8 bits.

The mini UART (default) on the Pi3 has the following features:
• 7 or 8 bit operation.
• 1 start and 1 stop bit.
• No parities.

It may be possible to find an external UART which supports more, although I am unaware of any. It is always possible to write a bit-banging emulation to support more (and there may be available libraries to do this).

See How-do-i-make-serial-work-on-the-raspberry-pi3 for more detail.

1

Some UART devices support more than 8 bits per character (e.g. PL2303 can transfer 16 bits at once), however, such transfer modes are unavailable on Linux with standard TTY driver. CSIZE (character size) field in terminal settings can only be between 5 and 8 bits, as per manual page.

If you're willing to write your own driver, you can pick a USB UART with a chip supporting more than 8 bits per character and use it. You'll have to write some C code, and probably your own Python library to get this working.

Another solution is to implement your own UART (e.g. using an Ardiuno) which would e.g. merge two successive characters into one and transmit it. You'll get to use standard drivers and libraries, but of course only compatible software which knows about characters merging (and thus sending twice as many characters) will be able to use it.

3
  • 1
    If you only need 9 bits per character (e.g. for talking to MDB controlled vending machines), you can set mark/space parity before sending the 8 "real" data bits. That gives you 9 bits, with the standard TTY driver and hardware
    – Janka
    Commented Jan 23, 2018 at 9:37
  • @Janka Nice find! Do you mind adding this to my answer, or writing your own? Commented Jan 23, 2018 at 9:44
  • It's already covered by the link in Ghanima's answer.
    – Janka
    Commented Jan 23, 2018 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.