2

I changed the baud rate of my linux USB port from 9600 to 115200 using the command # stty -F/dev/ttyUSB0 115200 because the FPGA that I am working on is programmed for a baud rate of 115200.

I cross-verified the new baud rate by using # stty -F/dev/ttyUSB0 -a. This gave me the following result:

speed 115200 baud; rows 0; columns 0; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

However, when I run my program the baud rate changes back to 9600 : python new.py Searching for interface... ['/dev/ttyUSB0']

ser: Serial(port='/dev/ttyUSB0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False).

What should I do?

2
  • 2
    You are not changing the speed of your system. You are changing the speed of one of its (real) terminal devices.
    – JdeBP
    Feb 28, 2019 at 11:51
  • 2
    Be sure to stop "ModemManager" or similar Services, which Access the Serial ports also.
    – gerhard d.
    Feb 28, 2019 at 13:28

2 Answers 2

5

If you don't mention the baud rate explicitly using pyserial, it would use 9600 as default. So the prior baud rate setting is of no use. Try echo hello > /dev/ttyUSB0 after setting for 115200 baud rate using stty command and the receiver to cat /dev/ttyUSBy.

4
  • Can you tell me how can I use pyserial to set my baud rate? Feb 28, 2019 at 23:15
  • 1
    Please use pyserial documentation
    – suren99
    Mar 1, 2019 at 6:25
  • I tried changing the baudrate by using pyserial , but it goes back to being 9600 once I execute my python code. I used the following code to change baudrate>>> import serial >>> ser=serial.Serial('/dev/ttyUSB0') >>> ser.name '/dev/ttyUSB0' >>> ser.baudrate 9600 >>> ser.baudrate= 115200 >>> ser.baudrate 115200 >>> ser Serial<id=0x7f8a74670a50, open=True>(port='/dev/ttyUSB0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False) Mar 1, 2019 at 11:50
  • what do you mean by "it goes back to 9600"?. According to the output you have posted i could see the baud rate has been changed to 115200.
    – suren99
    Mar 2, 2019 at 13:52
0

Pyserial doesn't support opening the port without changing the baud rate. If the baudrate parameter is not supplied, it will default to 9600.

You will need to pass the desired baudrate on each pyserial invocation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .