# 2 Raspberry Pi communicates via UART
設置與測試
---
- 設置使用 PL011 UART 來當成通訊介面
- Raspberry Pi 2 Model B
- 執行 raspi-config 以便 enable "PL011 UART"
- Disable "login shell to be accessible over serial"
- Enable "the serial port hardware"
- 確認 /boot/config.txt 中有以下內容
- enable_uart=1
- 檢查 /dev/serial0 -> ttyAMA0
- Raspberry Pi 3 Modeb B
- 同上,執行 raspi-config
- 確認 /boot/config.txt 中有
- enable_uart=1
- dtoverlay=pi3-miniuart-bt
- dtoverlay=pi3-disable-bt
- 檢查 /dev/serial0 -> ttyAMA0
- pin 腳對接 (GND/GND, TX/RX, RX/TX)
- 使用 minicom 進行測試
- minicom -b 115200 -o -D /dev/ttyAMA0
- Press Ctrl-A then E to enable local echo.
- Press Ctrl-A then A to enable linefeed.
- 兩端可進行通訊
- Press Ctrl-A then X to exit.
- 簡易使用 PySerial 進行測試 example
- [RPi Python Programming 19: Serial UART communication on RPi’s TTL port](https://www.engineersgarage.com/articles-raspberry-pi-serial-communication-uart-protocol-ttl-port-usb-serial-boards/)
Reference
---
- [UART通信的基礎](https://zechs.taipei/?p=127)
- [啟用Raspberry Pi 3B+ 序列埠功能](https://dumbcatnote.blogspot.com/2020/04/raspberry-pi-enable-serial-port.html)
- Raspberry Pi 3B+有兩個UART。分別為PL011 UART與mini UART,PL011使用獨立的硬體(ARM PrimeCell PL011)去控制傳輸的baud rate,所以傳輸的性能與穩定度都很好,但是mini UART的baud rate是使用系統核心時脈計算出來的,只能算半軟體的URAT,就算設定到115200bps實際上只有72000bps左右而已,相較之下效能與穩定度都不足。
- [RPi Python Programming 19: Serial UART communication on RPi’s TTL port](https://www.engineersgarage.com/articles-raspberry-pi-serial-communication-uart-protocol-ttl-port-usb-serial-boards/)
- the default serial Linux console on Raspberry Pi OS must be disabled to use RPi’s serial TTL port for UART communication. (sudo raspi-config)
- the serial TTL port (GPIO14 and GPIO15) are enabled for serial communication on Raspberry Pi
- After rebooting RPi, its serial TTL port can be used for serial communication over the UART protocol. The port can be addressed by name /dev/serial0.
- Alternatively, /dev/ttyS0 or /dev/ttyAMA0 can be used as port names, depending on whether PL011 or mini-UART is the primary UART. If in the /boot/config.txt file, the enable_uart flag is set to 0 by default, then the mini-UART is the primary UART on that RPi model. However, if the enable_uart flag is set to 1 by default, then PL011 is the primary UART on that RPi model.
- PySerial example.
- [Setting Up UART Serial Communication between Raspberry Pis](https://scribles.net/setting-up-uart-serial-communication-between-raspberry-pis/)
- 將二端的 TX/RX/GND 對接,記得 TX/RX 要交換,使用 minicom 測試
- [Raspberry Pi UART Communication using Python and C](https://www.electronicwings.com/raspberry-pi/raspberry-pi-uart-communication-using-python-and-c)
- [BCM2837 ARM Peripherals](https://datasheetspdf.com/pdf-file/1461568/Broadcom/BCM2837/1)
- P.102, Alternative Function Assignment
- [Raspberry Pi: overlay 的說明](
https://github.com/raspberrypi/linux/tree/rpi-4.1.y/arch/arm/boot/dts/overlays)
- 設置鏡像源 /etc/apt/sources.list
- [清华大学开源软件镜像站: Raspbian 镜像使用帮助](https://mirrors.tuna.tsinghua.edu.cn/help/raspbian/)
- [如何在Ubuntu Linux上選擇最快的apt鏡像](https://ubuntuqa.com/zh-tw/article/9003.html)
- [如何选择最快的树莓派软件更新源](https://www.basemu.com/how-to-choose-the-fastest-raspberry-pi-update-source.html)
- [Raspbian Mirrors](https://www.raspbian.org/RaspbianMirrors)
###### tags: `linux` `UART` `Raspberry Pi`