gonesurfing
Posts: 7
Joined: Wed Aug 22, 2012 1:13 am

9 bit serial

Fri May 31, 2013 10:19 pm

Hello all,

I have successfully been able to "listen in" to an early 90's vintage alarm system through modification of the Arduino software serial library to accept a non-standard baud rate and skip an interrupt bit. The interrupt bit appears after the 8 bits of data, but before the stop bit. By basically taking the software delay designed to skip the stop bit and multiplying by 2, I can ignore the 9th bit. I've also been able to pass the 9th bit on the output data, but so far it has not appeared useful.

My question... is there a way to do something similar with the pi, without having to use an arduino and interface? I read that the pl011 uart can possibly do 2 stop bits, but it appears that maybe that isn't readily available on the GPIO pins without some serious hacking? I've already read that by modifying one of the system clocks, the baud rate can be changed to something non standard. I can always fall back on the arduino "software serial" interface method, but it would be nice to be able to interface directly through the pi with a simple C program or perl script.

Thanks in advance.

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

Re: 9 bit serial

Sat Jun 01, 2013 12:02 am

In case you have read otherwise, the PL011 UART (not the Mini) is the one that is enabled by default and appears as ttyAMA0 in Linux.

You can send and expect two stop bits with termios flag CSTOPB. It does not appear to be a problem if the stop bits received are at the wrong level. Linux does not support nine bit data, but you can use eight bits plus parity (CS8|PARENB), and you do not have to check that parity is correct on input (INPCK). By combining these techniques you can ignore up to two junk bits before the stop bit.

This thread discusses non standard baud rates by adjusting the UART clock.

gonesurfing
Posts: 7
Joined: Wed Aug 22, 2012 1:13 am

Re: 9 bit serial

Sat Jun 01, 2013 3:35 am

This post towards the bottom of the thread, is the one I am referring to. The PL011 UART is mapped to GPIO pins 32/33 which don't exist anywhere on the board, despite showing up in the OS.

http://www.raspberrypi.org/phpBB3/viewt ... 44&t=13957

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

Re: 9 bit serial

Sat Jun 01, 2013 4:37 am

At boot, GPIO14/15 are ALT0, which is the PL011:

Code: Select all

[    0.584104] Serial: AMBA PL011 UART driver
[    0.584249] dev:f1: ttyAMA0 at MMIO 0x20201000 (irq = 83) is a PL011 rev3
The Mini UART would be at 0x20215000, but I do not think there are Linux drivers for it. It could be mapped to GPIO14/15 as ALT5, but obviously the PL011 is better.

It is true that you cannot connect both UARTs at the same time because GPIO32/33/36/37/41 are not brought out. (The transmit side of the Mini could be routed to GPIO40 if you were prepared to modify the board and remove the analogue audio components.)

gonesurfing
Posts: 7
Joined: Wed Aug 22, 2012 1:13 am

Re: 9 bit serial

Sun Jun 02, 2013 4:46 pm

Thanks. I've got it working now.

After modifying the uart clock in cmdline.txt I still had to configure the port with the following line.

sudo stty -F /dev/ttyAMA0 cstopb speed 4800

"cstopb" sets stop bits to "2" and speed is obvious. Now if I cat the device file, I get the expected output.

Return to “Interfacing (DSI, CSI, I2C, etc.)”