我在树莓派pi3上遇到了一个问题,我完美地使用了UART串行通信,但是我不知道发生了什么事情,现在使用了与我以前使用的相同的脚本,它无法正常工作。这次脚本没有任何响应。
我通过将串行通讯配置为/ dev / ttyAMA0来使该UART通讯正常工作,并使蓝牙也正常工作,一切正常,但突然却无法正常工作。
我使用的脚本是:
发件人脚本::
import serial
from time import sleep
ser = serial.Serial ("/dev/ttyAMA0", 9600) #Open port with baud rate
while True:
data = b'data to be send'
ser.write(data)
接收脚本::
import serial
from time import sleep
ser = serial.Serial ("/dev/ttyAMA0", 9600) #Open port with baud rate
while True:
received_data = ser.read() #read serial port
sleep(0.03)
data_left = ser.inWaiting() #check for remaining byte
received_data += ser.read(data_left)
print (received_data) #print received data
请帮助我解决此问题...
# dmesg | grep tty
[ 0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=1824 bcm2708_fb.fbheight=984 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200 root=PARTUUID=9e90e4f3-02 rootfstype=ext4 elevator=deadline
fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
[ 0.000283] console [tty1] enabled
[ 0.732898] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
[ 0.732962] console [ttyAMA0] enabled
[ 0.734618] 3f215040.serial: ttyS0 at MMIO 0x0 (irq = 166, base_baud = 31250000) is a 16550