I have bought Waveshare 2-CH RS485 HAT based on SC16IS752. 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
- 2x USB RS485 sticks (ttyUSB0 and ttyUSB1)
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 10 (buster)
Release: 10
Codename: buster
$ uname -a
Linux raspberrypi 5.10.17-v7+ #1403 SMP Mon Feb 22 11:29:51 GMT 2021 armv7l GNU/Linux
$ cat /boot/config.txt | grep sc16is752
dtoverlay=sc16is752-spi1,int_pin=24
Both ports on the RPi HAT configured to full auto mode. Here is a photo of the config 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
So, finally, I'm almost sure that this is software issue and hoping for some help. Advice, instructions, examples, at this point anything is welcomed to perhaps get me further.
I'm stuck, and any help is appreciated.
Thank you in advance