1

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

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Yuriy
  • 11
  • 1
  • I don't see anything wrong in your code. It seems to me this might be a driver issue. Have you tried the sample code from Waveshare? – Marcos G. Apr 26 '21 at 18:54
  • Thnx for your time. All Waveshare code is performing sequential operations. In this case all works as expected. Issue looks like buffer overflow, but I don't want to believe, that my case is the first attempt to make IO to ports in parallel. – Yuriy Apr 27 '21 at 15:25
  • Hello Yuriy. I agree it's quite surprising you are the first trying to run both ports concurrently... If you google the kernel driver for your device you will find a lot of issues but most of those were fixed. I don't have much else to add to be honest, I wish I had the device to test it... – Marcos G. Apr 27 '21 at 18:18
  • Have you succeeded solving this? I have two SC16IS752 boards on SPI0, they used to work, but after 2 months relax, now they are not. Even if I connect only one, both `SC0` and `SC1` are using ChannelA. – Daniel Oct 05 '21 at 12:28
  • The problem is that you're toggling the SPI select pin before all the data has been sent - you need to wait for sending to finish, before switching to the other device - or - see my answer below for the solution. –  Nov 08 '21 at 13:40

1 Answers1

0

SPI shares the bus. You can change one or both of the SC16IS752's to use I2C mode instead (see the datasheet for how to change the address on one of the modules if you opt for both using I2C) which will almost certainly bypass your problem.

  • See datasheet here: https://www.nxp.com/docs/en/data-sheet/SC16IS752_SC16IS762.pdf for the pins you need to solder to set I2C mode and address –  Nov 08 '21 at 13:42