What is minimum serial baud rate on (bullseye) Raspberry Pi OS (using python) and Raspberry Pi 4B?

huangapple go评论66阅读模式
英文:

What is minimum serial baud rate on (bullseye) Raspberry Pi OS (using python) and Raspberry Pi 4B?

问题

在我的设置中,我需要从传输速率为600波特的串行端口读取数据。我无法更改发送方的速率。在我的Raspberry Pi 3B+上,使用一年前未更新的图像(版本10 buster),它正常工作。但在使用我最新的Raspberry Pi 4B上(bullseye版本)和完全更新(2023年2月8日),它不起作用。

为了测试,我设置了自己的发送器,如果我以1200到115200波特传输和接收,它正常工作。但在600波特下,我只收到乱码。
我正在开发一种替代的驱动程序(使用Python),使用位操作读取GPIO引脚,在这个低速下应该是可能的,但它似乎非常不稳定。
我使用了/dev/serial0(引脚15作为RX),由于连接了其他硬件,这个串行端口/GPIO是我唯一的选择。

Python测试发送器代码:

import time
import serial
serialport2 = serial.Serial("/dev/ttyUSB1", 600, timeout=1, bytesize=8)
while True:
    sendDataStr = "YX"
    serialport2.write(sendDataStr.encode())
    time.sleep(0.1)
serialport2.close()

Python接收器代码:

import serial
serialport = serial.Serial("/dev/serial0", 600, timeout=1, bytesize=8)
while True:
    try:
        print(serialport.read())        
    except KeyboardInterrupt:
        serialport.close()
        break

Raspberry Pi 4B和Raspberry Pi OS的最低串行速度是否受到内核超时或类似问题的影响?有人知道Raspberry Pi 4B和Raspberry Pi OS已经测试过的最低速度是多少吗?是否有关于解决方法的任何想法?使用位操作的C驱动程序,或者完全不同的串行驱动程序,或者其他方法?
旧版buster上的Python版本: 3.7.3
新版bullseye上的Python版本: 3.9.2

英文:

In my setup I need to read from a serial port that transmits at 600 baud.
I can't change the transmitter speed.
Using my Raspberry Pi 3B+ with a years old un-updated image (version 10 buster) it works fine.
When using my Raspberry Pi 4B with the newest (bullseye) and fully updated (8th Feb. 2023) Raspberry Pi OS it doesn't work.

For test purposes I have setup my own transmitter and it works fine if I transmit and receive at 1200 to 115200 baud. But at 600 baud I just receive gibberish.
I am working on an alternative driver (using python) that reads the GPIO pin using bit-banging which should be possible at this slow speed but it seems very unstable.
I am using /dev/serial0 (pin15 as RX) and because of other connected hardware this serial port / GPIO is my only option.

Python test transmitter code:

import time
import serial
serialport2 = serial.Serial("/dev/ttyUSB1", 600, timeout=1, bytesize=8)
while True:
    sendDataStr = "YX"
    serialport2.write(sendDataStr.encode())
    time.sleep(0.1)
serialport2.close()

Python receiver code:

import serial
serialport = serial.Serial("/dev/serial0", 600, timeout=1, bytesize=8)
while True:
    try:
        print(serialport.read())        
    except KeyboardInterrupt:
        serialport.close()
        break

Is the slow serial speed hit by a kernel timeout or something along those lines?
Does anyone know what the minimum speed that Raspberry Pi 4B and Raspberry Pi OS has been testet at?
Any ideas for a workaround? Using a C-driver for bit-banging or a completely different serial driver or?
Python version on (old) buster: 3.7.3
Python version on (new) bullseye: 3.9.2

答案1

得分: 1

It seems the minimum baud rate is 1200 using standard configuration.
然而,这是使用“mini UART”,其功能有限。
So if the Bluetooth is not needed it is possible to swap the mini UART for the
所以,如果不需要蓝牙,可以将mini UART 替换为
PL011 UART which is a proper hardware implemented UART.
PL011 UART,这是一个适当的硬件实现的UART。
Add the following line to config.txt:
将以下行添加到config.txt文件中:

    # If using RPi3
    # 如果使用RPi3
    dtoverlay=pi3-miniuart-bt

    # If using RPi4
    # 如果使用RPi4
    dtoverlay=miniuart-bt

The "/dev/serial0" will now run at 600 baud without issues.
"/dev/serial0"现在将以600波特率运行,无问题。

英文:

It seems the minimum baud rate is 1200 using standard configuration.
However, this is using the 'mini UART' which has limited capabilities.
So if the Bluetooth is not needed it is possible to swap the mini UART for the
PL011 UART which is a proper hardware implemented UART.
Add the following line to config.txt:

    # If using RPi3
    dtoverlay=pi3-miniuart-bt

    # If using RPi4
    dtoverlay=miniuart-bt

The "/dev/serial0" will now run at 600 baud without issues.

huangapple
  • 本文由 发表于 2023年2月9日 03:13:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390659.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定