- Ensure terminal over serial is disabled in raspi-config
Run
sudo raspi-config
and in "Advanced" choose "Serial" (Enable/Disable shell and kernel messages on the serial connection) and disable it.
Steps 2 and 3 should not be necessary if you do this step first, but in case it didn't work - check them also.
- Ensure /boot/cmdline.txt has no ttyAMA0
The previous step should have already done that, but just in case do
cat /boot/cmdline.txt
and ensure its like this:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
and not like this:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
See also: http://elinux.org/RPi_Serial_Connection#S.2FW:_Preventing_Linux_from_using_the_serial_port
- Disable serial-getty properly if it's still running
If ps aux | grep tty still shows getty using ttyAMA0 - disable it, but don't do
sudo systemctl disable [email protected]
As explained here, the service may still run. Use this instead:
sudo systemctl mask [email protected]
- Ensure UART pins (15 and 16 wPi) are in state ALT0
Use command-line gpio util to check state of all pins
gpio readall
It should produce result like this
+-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5V | | |
| 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | ALT0 | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | ALT0 | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| 28 | 17 | GPIO.17 | IN | 0 | 51 || 52 | 0 | IN | GPIO.18 | 18 | 29 |
| 30 | 19 | GPIO.19 | IN | 0 | 53 || 54 | 0 | IN | GPIO.20 | 20 | 31 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
Note that Tx and Rx pins are in state ALT0.
- If in your case Tx and Rx pins are not in state ALT0, you can use same utility to manually change their state to ALT0. This should fix your problem until next reboot.
gpio mode 15 ALT0; gpio mode 16 ALT0
UPDATE:
- Enable uart in /boot/config.txt
In order to avoid manual step 5 and some issues that might occur with port ttyAMA0 not being found (/dev/ttyAMA0 being absent) you can set enable_uart=1 in /boot/config.txt, which seems to bring back /dev/ttyAMA0 and ports 15+16 are now in ALT0 state after reboot.