SC16is752 shared data between ports

Open
#4,344 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
c, linux

Research direction

Start with the linked pingpong test app and reproduce the two-process setup using ttySC0/ttyUSB0 and ttySC1/ttyUSB1 at 115200 baud. Compare the received buffers after failures and trace the SC16IS752 serial handling to determine why bytes cross between ports. Done means both port pairs remain independent under concurrent use.

Written by the indexing model from the issue text.

Description

I have SC16IS752-based HAT connected throught SPI (Waveshare 2-CH RS485 and Inno-Maker rs485-can) . In the project, this HAT was bought for, I need to send modbus commands into 2 different ports independently. After very short amount of time, I have found that sometimes app reading answers from another port.

To prove that, test configuration was built.
Here is a config:

  • RPi 3
  • Waweshare 2-RS485-HAT (ttySC0 and tyySC1)
  • 2x USB FT232RL-based RS485 sticks (ttyUSB0 and ttyUSB1)
$ cat /etc/rpi-issue
Raspberry Pi reference 2021-03-04
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 461109415073d2eb67083709662ba983cc191f14, stage2

$ vcgencmd version
Apr 30 2021 13:45:52 
Copyright (c) 2012 Broadcom
version d7f29d96450abfc77cd6cf011af1faf1e03e5e56 (clean) (release) (start)

$ uname -a
Linux raspberrypi 5.10.17-v7l+ #1414 SMP Fri Apr 30 13:20:47 BST 2021 armv7l GNU/Linux

Both ports on the RPi HAT configured to full auto mode.
ttySC0 wired to ttyUSB0 and ttySC1 wired to ttyUSB1.

Test app source: https://gist.github.com/asp24/8602ca080f2a3c2b1ec2a99a52074c0b

Idea is very simple: write some predefined buffer to the ttySC0, read it from the ttyUSB0, write back to the ttyUSB0, read from the ttySC0 and compare with original buffer.

If I am running application only for 1 pair of the ports - everything works for a few days. But if app started for both pair of the ports,- one of them will fail shortly

# Starting two separate processes
./pingpong -port1 /dev/ttySC0 -port2 /dev/ttyUSB0 -sendMessage '(abcdefghijklmn)' -portSpeed 115200 &
./pingpong -port1 /dev/ttySC1 -port2 /dev/ttyUSB1 -sendMessage '[ABCDEFJHIJKLMN]' -portSpeed 115200 &

Here is several application outputs after failures

>> (abcdefghijklmn) 
<< HIJKLMN]hijklmn) 
>> (abcdefghijklmn)
<< (abcdefghijk[ABC
>> (abcdefghijklmn)
<< (abcdefgh[ABCDEF

As you can see, part of the data from SCx has been read from SCy. Sometimes broken in the same way data also sent from the port.

Dominant language
C
Stars
13.2k
Forks
5.5k
Avg merge
2d 21h
Merged PRs (30d)
21

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/linux

All issues in raspberrypi/linux

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.