在Mobaxterm下,如果驱动安装成功,这个转换器可以识别的话,它会显示在rasp上对应 /dev/ttyS0,在电脑上是com7,所以网上教程上有 ttyAMA0 or ttyS6 等等是不对的
1,sudo raspi-config
2,cat /boot/cmdline.txt
里面不能有ttyAMA0,反正串口就是 ttyS0
3、如果有:
If ps aux | grep tty still shows getty using ttyAMA0 - disable it, but don't do
sudo systemctl disable serial-getty@ttyAMA0.service
the service may still run. Use this instead:
sudo systemctl mask serial-getty@ttyAMA0.service
- 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.