2

We need to use RS485 to talk to one of our custom tools. We need to use hardware controlled rts/cts. I've read so many articles about this but nobody ever says it works for them with fast timing and hardware controlled.

However, I can't get it working, I think it is being software controlled still because our timings are really long. RTS may be working but its changing weird. We are seeing 250us before and after, but not the values we want of 3.5us before and 1us after.

Here is what I have done:

  1. disabled and removed bluetooth completely.

  2. modified /boot/config.txt to add the following:

enable_uart=1
init_uart_clock=16000000
gpu_mem=256
dtoverlay=pi3-disable-bt
gpio=17=a3
dtoverlay=miniuart-ctsrts

I can then check to see that GPIO17 is in RTS0 mode:

root@raspberrypi:/# raspi-gpio get 17
GPIO 17: level=1 fsel=7 alt=3 func=RTS0
  1. modified boot/cmdline.txt to the following:
dwc_otg.lpm_enable=0 console=tty1 root=PARTUUID=7fa4337c-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
  1. ran this: https://github.com/mholling/rpirtscts

  2. I am using PySerial and working with rs485 in this way PySerial docs:

ser = serial.rs485.RS485(
     port='/dev/serial0', 
     baudrate=1000000, 
     timeout=0.1, 
     parity=serial.PARITY_NONE, 
     stopbits=serial.STOPBITS_ONE, 
     bytesize=serial.EIGHTBITS,
     xonxoff = False,     #enable software flow control
     rtscts = True,     #enable hardware (RTS/CTS) flow control
     dsrdtr = True,       #disable hardware (DSR/DTR) flow control
     write_timeout=0.1
)

ser.rs485_mode = serial.rs485.RS485Settings(
     rts_level_for_tx=False, 
     rts_level_for_rx=True, 
     loopback=False, 
     delay_before_tx=0.0000035, 
     delay_before_rx=0.0000001
)
  1. Here is my serial ports in /dev
root@raspberrypi:/dev# ls -al serial* ttyA*
lrwxrwxrwx 1 root root          7 Sep 17 09:47 serial0 -> ttyAMA0
lrwxrwxrwx 1 root root          5 Sep 17 09:47 serial1 -> ttyS0
crw-rw---- 1 root dialout 204, 64 Sep 17 10:15 ttyAMA0

The caveat is that this could be working,but maybe not observing the delays we have in place. I don't know if the Pi 4 hardware is even capable of these very fast times. Looking on an oscilloscope, I can see data but it isn't stopping as quickly as I have specified so that leads me to believe that hardware control isn't working and I am in still in software controlled mode.

A few pictures:

before data after data showing 1mb and 250us

setup

  • Why not check the RTS line? Surely the question will be different if RTS is being toggled properly? – joan Sep 17 at 17:00
  • @joan can you explain more what you mean? – JSMNST Sep 17 at 17:04
  • You say RTS is not working. RTS is a signal line connected to a GPIO and your hardware. Have you checked it is being set properly? – joan Sep 17 at 17:09
  • @joan rts is "working" but its changing weird. We are seeing 250us before and after, but not the values we want of 3.5us before and 1us after. – JSMNST Sep 17 at 17:15
  • That information needs to be edited into your question. You also need to add supporting evidence such as a scope display. – joan Sep 17 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.