When I test the RPi4 uart in loopback, it performs as expected. When I use a USB uart to talk with it, the serial stream is corrupted. The same USB uart works just fine on the RPi3B+.
The only difference is the RPi4 and RPi3B+.
Any ideas as to what could be happening would be appreciated.
Code: Select all
#!/usr/bin/python
import time
import serial
# configure the serial connections (the parameters differs on the device you are connecting to)
ser_0 = serial.Serial(
# port='/dev/ttyUSB0',
port='/dev/ttyS0',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
xonxoff=False,
rtscts=False,
dsrdtr=False
)
ser_1 = serial.Serial(
port='/dev/ttyUSB0',
# port='/dev/ttyS0',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
xonxoff=False,
rtscts=False,
dsrdtr=False
)
ser_0.isOpen()
ser_0.reset_input_buffer()
ser_0.reset_output_buffer()
ser_1.isOpen()
ser_1.reset_input_buffer()
ser_1.reset_output_buffer()
print 'Enter your commands below.\r\nInsert "exit" to leave the application.'
input=1
while 1 :
# get keyboard input
input = raw_input(">> ")
# Python 3 users
# input = input(">> ")
if input == 'exit':
ser_0.close()
ser_1.close()
exit()
else:
# send the character to the device
ser_0.write(input)
out = ''
# let's wait one second before reading output (let's give device time to answer)
time.sleep(1)
while ser_1.inWaiting() > 0:
out += ser_1.read(1)
if out != '':
print "ser_1 rx >>" + out
ser_1.write(input)
out = ''
# let's wait one second before reading output (let's give device time to answer)
time.sleep(1)
while ser_0.inWaiting() > 0:
out += ser_0.read(1)
if out != '':
print "ser_0 rx >>" + out