Traduit de English par IA ·
Le point d’Emily fait partie du problème. Le reste, c’est le jeu de permutation des UART du Pi 3, qui piège tout le monde.Les Pi 3/4/Zero W disposent de deux UART. ttyAMA0 est le PL011, le bon, avec sa propre horloge. ttyS0 est le mini UART, dont le débit en bauds est dérivé de l’horloge du cœur VPU ; quand l’horloge du cœur varie, le débit dérive, et c’est exactement ce qui provoque vos erreurs CRC une fois sur cinq. Sur ces modèles, le PL011 est par défaut relié au Bluetooth intégré et l’en-tête GPIO reçoit le mini UART. /dev/serial0 est un alias qui pointe toujours vers celui qui se trouve sur GPIO14/15.Donc, selon votre configuration, vous parliez soit à la puce Bluetooth, soit au mini UART. Rendez le PL011 à l’en-tête :
# /boot/firmware/config.txt (Bookworm)
enable_uart=1
dtoverlay=disable-bt
sudo systemctl disable hciuart
# et supprimez console=serial0,115200 de /boot/firmware/cmdline.txt
sudo reboot
Ensuite, ouvrez /dev/serial0 dans votre script, pour que tout continue de fonctionner si vous passez à un autre modèle. Vous perdez le Bluetooth intégré, ce qui, sur un boîtier de relevé de compteurs, ne vous manquera pas.Si vous avez besoin du Bluetooth, l’autre option est core_freq=250 pour figer l’horloge du mini UART, mais je préfère nettement le PL011.
Emily’s bit is part of it. The rest is the Pi 3 UART shuffle, which catches everyone.
The Pi 3/4/Zero W have two UARTs. ttyAMA0 is the PL011, the good one with its own clock. ttyS0 is the mini UART, whose baud rate is derived from the VPU core clock, so when the core clock moves the baud drifts and you get exactly your one-in-five CRC errors. On those models the PL011 is wired to the onboard Bluetooth by default and the GPIO header gets the mini UART. /dev/serial0 is an alias that always points at whichever one is on GPIO14/15.
So depending on your config you were either talking to the Bluetooth chip or to the mini UART. Give the PL011 back to the header:
# /boot/firmware/config.txt (Bookworm)
enable_uart=1
dtoverlay=disable-bt
sudo systemctl disable hciuart
# and remove console=serial0,115200 from /boot/firmware/cmdline.txt
sudo reboot
Then open /dev/serial0 in your script, so it keeps working if you move to another model. You lose onboard Bluetooth, which on a meter-reading box you don’t miss.
If you need Bluetooth, the other option is core_freq=250 to pin the clock for the mini UART, but I’d rather have the PL011.

