dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

RPi 3 -> Serial port issue

Mon Nov 19, 2018 1:33 pm

Hello there!

I am a newbie posting here, so please forgive me beforehand if this topic is replicated somewhere.

Back to the main point, I have already worked with RPis before, so I will try to explain the issue found as simple as I possible:

- I have a LoRa module connected to GPIO14 and GPIO15 (UART_TX - UART_RX), and also I have a python script using pyserial which is continuously sending commands through serial port in order to receive LoRa packets (that is to say, a simple receptor device).
- This is going perfectly until something bizarre happens always in an hour more or less: the serial port stops working without any reason, and it can only be recovered by killing the script and starting it again.
- The first I thought was a buffer size, but I am flushing both input and output lines everytime, so I presume that this could be discarded.

What it could be? Is any configuration that should be done? Is it something that I am missing?

Thanks for your time. Looking forward to hearing from you soon.

Best regards.
Daniel.

Paul Hutch
Posts: 402
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: RPi 3 -> Serial port issue

Mon Nov 19, 2018 2:16 pm

There are many possible causes for that symptom. Assuming you don't have serial data monitoring equipment to see exactly what is happening, I'd start by making sure there are timeouts on the wait for data to be received. Also I'd make sure the Pi only sends another command after it has received a reply for the previous command, or the timeout has occurred and you've handled the timeout error.

User avatar
bensimmo
Posts: 4184
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: RPi 3 -> Serial port issue

Mon Nov 19, 2018 3:35 pm

Just for some background info if others can help.
What LoRa module?
can you give the contents of (wrap the text in Code formatting)
/boot/config.txt
/boot/cmdline.txt

then we know your basic setup.

dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

Re: RPi 3 -> Serial port issue

Mon Nov 19, 2018 4:11 pm

Hello there!

Thanks for all your answers!

[*] Paul:
Paul Hutch wrote: There are many possible causes for that symptom. Assuming you don't have serial data monitoring equipment to see exactly what is happening, I'd start by making sure there are timeouts on the wait for data to be received. Also I'd make sure the Pi only sends another command after it has received a reply for the previous command, or the timeout has occurred and you've handled the timeout error.
- I believe that the command exchange procedure should not be the issue, because I have tried many programming possibilities without any good result... Anyway, I will revise it again!
Furthermore, the serial timeout has been set to 20 in order to have another exit way in stuck cases, just in case.

[*] Bensimmo:
bensimmo wrote: Just for some background info if others can help.
What LoRa module?
can you give the contents of (wrap the text in Code formatting)
/boot/config.txt
/boot/cmdline.txt

then we know your basic setup.
- Sure thing! The LoRa module is the RN2483, from Microchip.
- Content for /boot/config.txt file

Code: Select all

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
#dtparam=audio=on

# Disable BT
#dtoverlay=pi3-disable-bt
- Content for /boot/cmdline.txt file

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=08a73f7d-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
I hope this information may help, and if not, do not hesitate to ask for further!

Looking forward to hearing from you.

Best regards.
Daniel.

HiassofT
Posts: 221
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: RPi 3 -> Serial port issue

Mon Nov 19, 2018 5:13 pm

dperez wrote:
Mon Nov 19, 2018 4:11 pm
- Content for /boot/cmdline.txt file

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=08a73f7d-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
Remove "console=serial0,115200" from cmdline.txt, as described in the wiki https://www.raspberrypi.org/documentati ... on/uart.md
In a default install of Raspbian, the primary UART (serial0) is assigned to the Linux console. Using the serial port for other purposes requires this default behaviour to be changed.
so long,

Hias

User avatar
bensimmo
Posts: 4184
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: RPi 3 -> Serial port issue

Mon Nov 19, 2018 6:37 pm

That a above, remove console=serial0,115200
As other data will be fed to the port (I'm surprised it allows you to use it, iirc it takes command of the poet and gives errors if you try to open a connection.

I see you are using the 'full' UART, so that can be ruled out. (Disable BT)

I see that is # out so you actually have not serial port enabled (I cannot see the other setting to enable it).

Is this SPI and not UART?

But then you wouldn't be using pin 14/15, confused.

dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

Re: RPi 3 -> Serial port issue

Tue Nov 20, 2018 8:03 am

Hello there!

Thanks for your support!

I have removed the "console=serial0,115200" line as suggested... but, I have bad news. I have opened the box where the device is, and to my surprise, it is not following the specifications written weeks ago -> This is thanks to bensimmo last post.

What does that mean? It means that the device is not connected to UART0 but to one USB... So, it changes the perspective of the issue I am afraid.

Sorry for the inconveniences, I should have revised this before but I did not want to modify the job done by another colleague.

Looking forward to your feedback.

Best regards.
Daniel.

User avatar
bensimmo
Posts: 4184
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: RPi 3 -> Serial port issue

Tue Nov 20, 2018 11:51 am

that would change things.
is it on /dev/ttyUSB0 then, it should be easier, I guess you would need to know the USB chip on the board.

dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

Re: RPi 3 -> Serial port issue

Tue Nov 20, 2018 1:24 pm

Hello!

The RPi-USB is plugged with this sort of FTDI:
https://www.ftdichip.com/Support/Docume ... CABLES.pdf

And on the other side, the cable has been cut in order to be soldered in the LoRa module.

I hope this could give you clues.

Best regards.
Daniel.

Paul Hutch
Posts: 402
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: RPi 3 -> Serial port issue

Tue Nov 20, 2018 2:05 pm

When I saw that enable_uart=1 was not in your config.txt yesterday I knew that you could not be using the built-in UART but didn't have time to reply. Good to see you've got that part sorted out.

The advise in my previous post applies just as much to the USB UART you are actually using. To carry out the previous advice you should make sure you track the state of the connection in your code, log state changes and any any errors that your code encounters. This can be done by writing to the system logs, custom log files, or simply printing the text to a console.

dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

Re: RPi 3 -> Serial port issue

Wed Nov 21, 2018 7:30 am

Hello,

After writing some information lines, I left the program running by its own yesterday, and this is the response from the script when he got stuck:

Code: Select all

Tue Nov 20 17:58:48 2018
command response 1: ok

command response 2: radio_err

Tue Nov 20 17:59:08 2018
command response 1: ok

command response 2: radio_rx  31302C322C313531343736343837302C312C302C32312E352C35332C32312E300A

Tue Nov 20 17:59:14 2018
command response 1: ok

device reports readiness to read but returned no data (device disconnected or multiple access on port?)
Tue Nov 20 17:59:34 2018
^CTraceback (most recent call last):
  File "test_LSK.py", line 114, in <module>
    ret = ser.readline()
  File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 483, in read
    ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
KeyboardInterrupt
I will look for further information about this kind of python error, but it seems that somehow, the serial bus stops working without any known reason. I hope that somebody had had this issue already and could give me further information about it.

Looking forward to hearing from you.

Best regards.
Daniel.

Paul Hutch
Posts: 402
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: RPi 3 -> Serial port issue

Wed Nov 21, 2018 4:21 pm

Getting a descriptive error message is a very useful result. Unfortunately with that particular message there are many possible sources for the problem but the good news is that to me it most likely does rule out your python code as the problem.

A few of the possible sources of a "(device disconnected or multiple access on port?)" error in no particular order are:
  • Intermittent noise pickup on the TTL wires
  • Intermittent fault in the USB to TTL serial adapter
  • Intermittent fault in the driver for the USB to TTL serial adapter
  • Another process accessing the USB port where the adapter is plugged in
  • Another process accessing the serial port
  • Your code using multiple threads and accidentally attempting to access the port from two threads at once
  • Design flaw in the USB to TTL serial adapter that only appears intermittently
How you attack this is very dependent on your particular application. If all you want is to stop the hangups then simply trapping that error in your code is a simple option. The last two posts in the following forum thread link show simple traps for a similar error in an application that can just keep running after that error.
viewtopic.php?t=201976#p1256252

You might want to close the port then reopen it or do other cleanup instead of just ignoring the error like the other thread shows.

dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

Re: RPi 3 -> Serial port issue

Wed Nov 21, 2018 4:29 pm

Hello there,

I made another test and this was its result:

Code: Select all

Wed Nov 21 11:01:28 2018
command response 1: ok

comand response 2:
radio_err

Wed Nov 21 11:01:48 2018
command response 1: ok

comand response 2:
`▒8|▒`>▒|Ɯ▒▒▒|`▒
Wed Nov 21 11:02:30 2018
command response 1:
NO response 2
----------------------------------
first message from reset: ▒8▒▒8▒▒
second message from reset:
cmd> radio set mod fsk

cmd> radio set freq 915000000

cmd> radio set pwr 20

cmd> radio set SF ...
After having the "NO response 2" message, a LoRa reset and configuration procedure are executed again. It means that the issue should be on the serial side, because the module has to answer "ok" to this command sequence... and unfortunately, it is answering nothing.

Right case:

Code: Select all

----------------------------------
first message from reset: RN2903 0.9.8 Feb 14 2017 20:17:03

second message from reset: RN2903 0.9.8 Feb 14 2017 20:17:03

cmd> radio set mod fsk
ok

cmd> radio set freq 915000000
ok

cmd> radio set pwr 20
ok

cmd> radio set SF
ok

cmd> radio set bw 250
ok

cmd> mac pause
4294967245

cmd> radio set wdt 20000
ok

----------------------------------
I hope this give clues, meanwhile I will keep working on it and testing your answers!!

Best regards.
Daniel.

Paul Hutch
Posts: 402
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: RPi 3 -> Serial port issue

Wed Nov 21, 2018 6:06 pm

Garbage characters when you expect ASCII are very often a sign of noise corrupting the data stream. If the TTL wires are more than a few inches long try shortening them or shielding them.

dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

Re: RPi 3 -> Serial port issue

Thu Nov 22, 2018 7:29 am

Hello!

I am attaching a picture where it can be seen the cable's length

Image

If that were the issue, I would have to be seriously worried, since I have used long FTDI cables (around 1 meter and a half) with other devices without any troubles.

Looking forward to your answers.

Best regards.
Daniel.

Paul Hutch
Posts: 402
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: RPi 3 -> Serial port issue

Thu Nov 22, 2018 2:12 pm

That looks shielded so that helps but keep in mind TTL was designed/engineered only for short distance runs on PCB tracks, not for any wire length at all, that's why TIA-232, USB, IEEE 1284, I2C, etc. exist.

If the character corruption isn't due to noise, I'd try a new USB/TTL cable, new Raspberry Pi, and new LoRa module. If the corruption still happens then it must be a design flaw in the LoRa module or bugs in the drivers or other system software so I'd write sufficient code to detect and recover from the corruption.

dperez
Posts: 8
Joined: Mon Nov 19, 2018 12:55 pm

Re: RPi 3 -> Serial port issue

Thu Dec 13, 2018 8:17 am

Hello there,

Sorry for answering so late, I was on a bussines trip. I would really like to test another device with new components and applying a change: the FTDI cable will be connected directly to the RPI UART pins... but unfortunately, the project it's right now in an stand off, so I do not know when we will go to take it back.

It is a shame, because I wanted to know the reason for later uses... we will see.

Thanks for all your answerings.

Best regards.
Daniel.

Return to “General discussion”