Posts: 1
Joined: Sun Oct 07, 2018 1:13 pm

Reset the serial port without rebooting

Sun Oct 07, 2018 1:24 pm


I'm using a Raspberry PI Zero W to communicate with another device over the serial port. Essentially, I'm facing the same issues as the unsolved thread in ... p?t=110501 .

To make it short:

Serial communication works perfectly. I fire up screen (screen /dev/ttyS0 9600) and communicate with no apparent errors. It'll work for a day, two days, five days, but eventually it'll break down. The other end can still receive what I type, but I can no longer read what I'm receiving. No amount of text sent, or time waited seems to fix it. Rebooting the PI immediately solves the problem.

Because it's not the other end (since rebooting the PI restores functionality and the other device does not even realize the PI was rebooted), I assume it's a problem on the PIs end - maybe an issue with synchronization - I wouldn't know. My question is, whether, and how, it is possible to just reset the serial port, without rebooting. Just forget the whole state, and start anew.

Just to anticipate a few questions that were asked in the other thread - the baud rate is 9600, the cable is unshielded, goes to the moon and back, while spinning seven loops around a mains voltage cable, and the voltage level gets adjusted eighteen times. The point is, it works - for a really long time. It still works one-way (to the other end) when it breaks down. Okay, it desyncs. No problem. Can the port be reset without "sudo reboot"ing the PI?

Posts: 1594
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Reset the serial port without rebooting

Sun Oct 07, 2018 4:02 pm

I would look to use a level sifter to 'true' RS/232 levels ±7.5v ish - something like the MAX232 then replace the wet string with a proper shielded cable and come back if that does not help :lol: :lol: :lol:

In the meantime, if you have a command line at the far end when the link 'dies', try

Code: Select all

stty echo
and see if that helps - its possible noise or corrupt data on the line is turning the echo off rather than a sync issue. With sync problems you normally get random characters at either / both end(s) at some point.

Another possibility is to try the software flow control on the screen command (no Pi handy to check if this works on the Pi)

Code: Select all

screen /dev/ttyS0 9600,cs8,ixon,ixoff
Have you changed the speed to 1200 to see if that helps?

Of course it could be a bug in the hardware or software :?

My wish for the Pi 4 would be a REAL serial port with DTS / RTS etc etc - I hate two wire interfaces for serial comms away from the work bench.
Need Pi spray - these things are breeding in my house...

User avatar
Posts: 2059
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Reset the serial port without rebooting

Sun Oct 07, 2018 4:06 pm

Do you need to stay connected all the time? Basic serial ports don't have a concept of sync: they're asynchronous, lacking a clock to set sync. Disconnecting and reconnecting may not be ideal: some devices trickle data all the time, while others (mostly Arduinos) reset on new connections. You can reset a serial port to 9600 8N1 using this command:

Code: Select all

stty -F /dev/ttyS0 9600 cs8 -cstopb -parenb
Have you tried a different terminal program, such as minicom? It has a few more easily-accessed serial tools, possibly including serial reset. There's a chance the problem is with the serial device itself: Arduino Leonardos and Micros have been known to do odd things after a couple of weeks runtime. Finally, it could well be your long unshielded cable. It may be picking up electrical noise that's being interpreted as a control code (Ctrl-S - 0x13 - is an especial favourite for breaking serial comms). It may just be too long, too. 15 m is about as long as is typically reliable with non-TTL RS-232 levels.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “Interfacing (DSI, CSI, I2C, etc.)”