Daniel.V
Daniel.V

Reputation: 2492

changing the baud rate of a serial port on a raspberry pi 3

I installed lineage os 14 on raspberry pi 3 I connected a gps module with UART port, however, the baud rate of GPS is 9600 but baud rate of /dev/ttyS0 is 115200 I want to change the baud rate of ttyS0 in order to read GPS data I tried stty command

stty -F /dev/ttyS0 9600

However, this won't change the baud rate when I check again with this command
stty -F /dev/ttyS0 the speed value is 115200. How can I change the baud rate of /dev/ttyS0 I also find some solution with serial command serial /dev/ttyS0 9600 however it doesn't exist on adb shell.Any help would be grateful

Upvotes: 5

Views: 12373

Answers (2)

Seamus
Seamus

Reputation: 223

Note that there is a hardware diff between Pi 3 & 4 and other Pis (0, 1, 2) where uart is concerned (ref the docs).

RPi 3 uses UART0 as its secondary/Bluetooth uart, and the miniUART as its primary uart. The primary/secondary designation has to do with where the uart is pinned out; primary means it's pinned out on GPIO 14 & GPIO 15, secondary means it's pinned out next to the WiFi/BT chip.

And so I suspect that the OP is connected to GPIO 14 & 15 (i.e. the miniUART on an RPi 3). And while the command (stty -F /dev/ttyS0 9600) does set the baud rate on the miniUART, this setting is based on the variable VPU clock. In other words, using the miniUART requires the RPi be configured to use a fixed VPU core clock frequency, which may be set up in /boot/config.txt using the enable_uart=1. (Note also that the given configuration settings are for bookworm, and are different for bullseye (see /boot/overlays/README) for details.)

And yes - this is confusing!

Upvotes: 1

Sky
Sky

Reputation: 4370

You will need to modify the /boot/config.txt file and add the following entry which enables serial line and specifies baud rate:

console=ttyAMA0,9600

That works for me.

Upvotes: 2

Related Questions