UART Issue


11 posts
by GHPoe105 » Sun May 15, 2016 6:00 am
I've been racking my brain on this one, I'm wondering if anyone can offer any ideas to whats going on?

I can confirm my UART is working during startup when the boot messages are being displayed. Once I disable the boot message logging (in sudo raspi-config, advanced, ...), and write a python script (found on elinux)

Ex:
import serial
port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)
while True:
port.write("\r\nSay something:")

I get no output on the TXD line. (reverting back to the boot msg logging causes normal behavior during startup)

The problem is I can't have the boot process holding onto that device because I would like to send my own messages.

Thanks,
Greg
Posts: 4
Joined: Sun May 15, 2016 5:46 am
by GHPoe105 » Sun May 15, 2016 8:44 pm
Here are some more details that might be relevant.

Running a Raspberry Pi Model 2 on distro Raspbian (jessie).

The following are my notes up to this point.

Steps to fix Raspberry even though a US keyboard was selected during installation
After Install to fix the keyboard \ and # characters
sudo setxkbmap -layout us
sudo reboot

To disable serial logging during boot
sudo raspi-config
Adv->Disable Serial Logging
sudo reboot

To install minicom
sudo apt-get install minicom

To test with minicom with TXD and RXD jumpered
minicom -b 9600 -o -D /dev/ttyAMA0
Posts: 4
Joined: Sun May 15, 2016 5:46 am
by rzusman » Sun May 15, 2016 11:58 pm
You probably also need to disable the getty process, too.
Google for it.
Posts: 282
Joined: Fri Jan 01, 2016 10:27 pm
by GHPoe105 » Mon May 16, 2016 12:45 am
rzusman wrote:You probably also need to disable the getty process, too.
Google for it.


This was done in the following command.
sudo raspi-config

dmesg | grep tty

also confirmed that the 'console [ttyAMA0] enabled' was not present.
Posts: 4
Joined: Sun May 15, 2016 5:46 am
by fivdi » Mon May 16, 2016 7:13 am
I can verify that this is an issue on the Raspberry Pi 2 with the latest version of Raspbian Jessie (2016-05-10.) On previous versions of Raspbian Jessie the behavior was different.

On previous versions of Raspbian Jessie disabling shell and kernel messages on the serial connection did disable the messages, but it didn't disable UART0/ttyAMA0 on GPIOs 14 and 15. It was still possible to use UART0/ttyAMA0 as GPIOs 14 and 15 remained in mode ALT0. The pin modes can be seen with the command "gpio readall".

On Raspbian Jessie 2016-05-10 things have changed. Disabling shell and kernel messages on the serial connection disables the messages, but it also disables UART0/ttyAMA0 on GPIOs 14 and 15 (or more correctly it probably never enables UART0 in the first place.) It's no longer possible to use UART0/ttyAMA0 as GPIOs 14 and 15 are configured as INPUT pins.

What is the easiest way to enable UART0/ttyAMA0 on a Raspberry Pi 2 with Raspbian Jessie 2016-05-10?
Posts: 155
Joined: Sun Sep 23, 2012 8:09 pm
by joan » Mon May 16, 2016 7:49 am
fivdi wrote:...
What is the easiest way to enable UART0/ttyAMA0 on a Raspberry Pi 2 with Raspbian Jessie 2016-05-10?

One way would be to set them to mode ALT0.

sudo pigpiod

pigs m 14 0 m 15 0 # Set GPIO 14/15 to ALT0
User avatar
Posts: 12657
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by fivdi » Mon May 16, 2016 8:09 am
@joan now that Raspbian Jessie comes with pigpio out of the box that is an option. I just tried it an it works. By the way joan, congratulations on that achievement, pigpio is an excellent piece of software.

On the other hand, I really think that there should be a dt-overlay for this purpose.

@PhilE if you happen to read this, what do you think? Should there be a dt-overlay for enabling UART0/ttyAMA0 on the Pi 2?
Posts: 155
Joined: Sun Sep 23, 2012 8:09 pm
by joan » Mon May 16, 2016 8:13 am
fivdi wrote:@joan now that Raspbian Jessie comes with pigpio out of the box that is an option. I just tried it an it works. By the way joan, congratulations on that achievement, pigpio is an excellent piece of software.

On the other hand, I really think that there should be a dt-overlay for this purpose.

@PhilE if you happen to read this, what do you think? Should there be a dt-overlay for enabling UART0/ttyAMA0 on the Pi 2?

The UART sounds like a temporary configuration problem to me - I can't see that this is intended behaviour.
User avatar
Posts: 12657
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by fivdi » Mon May 16, 2016 8:34 am
I think the behavior on Raspbian Jessie 2016-05-10 is correct and better than the behavior on previous version of Raspbian. If shell and kernel messages are disabled on the serial connection it looks like Raspbian Jessie 2016-05-10 will not enable UART0 on boot and will not transmit any information on UART0, which is good.

In previous versions of Raspbian Jessie disabling shell and kernel messages on the serial connection only partially worked. A small amount of information was still transmitted, for example, this: "Uncompressing Linux... done, booting the kernel."
Posts: 155
Joined: Sun Sep 23, 2012 8:09 pm
by esr » Tue May 17, 2016 2:10 am
root@ar:/# pigpiod
root@ar:/# pigs m 14 0 m 15 0
root@ar:/# stty -F /dev/gpsd0 raw 9600 cs8 clocal -cstopb
root@ar:/# cat /dev/gpsd0
root@ar:/#

The workaround failed for me. (/dev/gpsd0 is a symlink to /dev/ttyAM0).

Even if it had succeeded, this "feature" is idiotic. Silently disabling the UART pins during bootup might not be a terrible idea in itself, but why leave them disabled after boot? And why not tweak the device-open code to force the UART pins to at0 so the user doesn't need to take a special, undocumented action to use the UART?

Because of this "feature" and the workaround failing, I'm going to have to tell users to get a down-version Raspbian image in the HOWTO I'm writing. That's a hassle they didn't need.
Posts: 1
Joined: Tue May 17, 2016 1:31 am
by GHPoe105 » Tue May 17, 2016 3:19 am
Thanks everyone, I to have confirmed that running the following commands gets the UART working.

sudo pigpiod
pigs m 14 0 m 15 0 # Set GPIO 14/15 to ALT0
Posts: 4
Joined: Sun May 15, 2016 5:46 am