ttyAMA0, ttyS0, serial0: which one should my Modbus HAT use on a Pi 3B+?
Pi 3B+, Raspberry Pi OS Bookworm, an RS485 HAT on the GPIO header. Python with minimalmodbus polls a three-phase energy meter at 9600 8N1, address 5, and publishes kW and kWh to Hermetry every minute.
Problem: about one poll in five fails. Either a timeout or a CRC error. The same meter on a USB-RS485 stick on my laptop answers every time. My script opens /dev/ttyAMA0 because that’s what the HAT vendor’s example used. Then I read a forum post saying to use ttyS0, and another saying serial0, and now I honestly don’t know what ttyAMA0 even is.
minimalmodbus.NoResponseError: No communication with the instrument (no answer)
minimalmodbus.InvalidResponseError: Checksum error in rtu mode: 'x8ax1f' instead of 'x0exc4' .
What’s the difference and which one do I want?
Is ttyAMA0 a USB thing? I always thought ACM/USB names were for USB.
Not USB. I had flaky Modbus on a Pi 3 once and part of the fix was taking console=serial0,115200 out of cmdline.txt, the login console was sharing the port. Not sure that’s your whole problem though.
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.
disable-bt plus removing the console did it. 600 polls overnight, zero CRC errors, zero timeouts. I was on ttyAMA0 talking to… nothing useful apparently, and the script fell back to retries that sometimes hit. Changed it to serial0. Kevin, ttyAMA is the ARM PL011 naming, not USB.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

