tom_mezzy
Hello all.
 I would like to get data from Modbus RTU device using RS485. I found this hat:
www.waveshare.com/wiki/2-CH_RS485_HAT
which utilizes SPI interface. Would it be possible to configure this as slave device in  OpenPLC and use standard Modbus registers for reading/writing?
From what I seen waveshare provides some sample python code to get use this hat, but I was hoping to use it as hardware extension rather writing custom driver in python.
Reply 0 0
thiagoralves
No, that won’t work on OpenPLC, unless you write a driver using PSM. OpenPLC can only control built in serial ports for Modbus RTU. So for example, if you insert a USB 485 adapter that is compatible with Linux, since Linux already has a driver for that it will be enumerated as a normal serial port and OpenPLC will be able to use that natively
Reply 0 0
tom_mezzy
Though so. It looks like better option would be RS485 to Ethernet converter. I believe this should be visible from OpenPLC as standard Modbus TCP slave device?
Reply 0 0
thiagoralves
Most likely yes, but I bet a 485 USB adapter will be a lot cheaper.
Reply 1 0
tom_mezzy
That's good point. I think those usb converters can handle multiple Modbus devices simultaneously?
Reply 0 0
thiagoralves
That’s more on software than hardware. The module only needs to deliver messages on the bus. The software is the part handling multiple slaves
Reply 0 0
tom_mezzy
Ok, thanks for the tips.
BTW OpenPLC is a great piece of software and an idea.
Reply 1 0
Chrismettal
I've had success using an ISO3082 RS485/Modbus transceiver natively with the Pi, hooked up through UART0.
 
 
To switch the drivers on/off respectively, I am currently using a forked libmodus version as described in the following post, and I am yet to order boards of Rev.2 where automatic DE/NRE switching is optionally on-board as well, but any RS485 transceiver should work well natively through a Pi's UART without any hardware driver written.
 
Reply 1 0
Mange
No, that won’t work on OpenPLC, unless you write a driver using PSM. OpenPLC can only control built in serial ports for Modbus RTU. So for example, if you insert a USB 485 adapter that is compatible with Linux, since Linux already has a driver for that it will be enumerated as a normal serial port and OpenPLC will be able to use that natively
And same goes for this one then, which I bought? https://www.waveshare.com/rs485-can-hat.htm
These HATs are generally only needed for long distance modbus , and are really not needed when the slaves are within some meter or so?
Reply 0 0
thiagoralves
If the hat uses the built in serial port on the Pi it might work. The problem could be only on flow control which is required by RS485. That’s why USB adapters usually works best.
Reply 0 0
Mange
If the hat uses the built in serial port on the Pi it might work. The problem could be only on flow control which is required by RS485. That’s why USB adapters usually works best.
OK, but it is only connected to the GPIO of the PI so should work then? What means with flow control? Can I expect to have that from my slave (the inverter)?
Reply 0 0
thiagoralves
RS485 is half duplex in nature, which means there is only one line for both receive and transmit. Therefore you need an extra pin to control when you want to speak to avoid conflict in the line. If your hat requires this pin from the Pi GPIO then most likely it won’t work, because OpenPLC modus driver does not provide logic for a flow control pin. USB to RS485 adapters do that automatically based on the usb traffic, so there is no need for the Pi to control the flow.
Reply 0 0
Mange
RS485 is half duplex in nature, which means there is only one line for both receive and transmit. Therefore you need an extra pin to control when you want to speak to avoid conflict in the line. If your hat requires this pin from the Pi GPIO then most likely it won’t work, because OpenPLC modus driver does not provide logic for a flow control pin. USB to RS485 adapters do that automatically based on the usb traffic, so there is no need for the Pi to control the flow.
OK, thanks for the explanation. I think the last sentence says that its not required to control the communication? :
 
 
The RS485 CAN HAT will enables your Pi to communicate with other devices stably in long-distance via RS485/CAN functions.

Features

  • Standard Raspberry Pi 40pin GPIO header for Raspberry Pi series boards.
  • CAN function, onboard CAN controller MCP2515 via SPI interface, onboard transceiver SIT65HVD230DR.
  • RS485 function, controlled via UART, half-duplex communication, supports automatic TX/RX control without programming, onboard transceiver SP3485.
  • Onboard TVS (Transient Voltage Suppressor), effectively suppresses surge voltage and transient spike voltage in the circuit for RS485 transceiving, lightningproof & anti-electrostatic.
  • Reserved control header, allows working with other control boards.
  • Comes with online development resources and manual (examples in wiringPi/python).

Specification

  • Operating voltage: 3.3V
  • CAN chip: MCP2515
  • CAN transceiver: SN65HVD230
  • 485 transceiver: SP3485
  • Dimensions: 65mm x 30mm
  • Mounting hole size: 3.0mm

Onboard Interface

  • CAN Bus:
Function PINRaspberry Pi (BCM)Description
3V33V33.3V Power Input
GNDGNDGround
SCKSCKSPI Clock Input
MOSIMOSISPI Data Input
MISOMISOSPI Data Output
CSCE0Data/Command Selection
INT25Interrupt Output
  • RS485 Bus:
Function PINRaspberry Pi (BCM)Description
3V33V33.3V Power Input
GNDGNDGround
RXDRXDUART Receives
TXDTXDUART Transmits
RSE4Tx/Rx Control
For the RSE pin, you can choose not to use it, the module factory defaults to use the hardware automatic receive and transmit.
 
 
Reply 0 0
Mange
I take the silence as it is worth give it a try then. And it is in fact not possible to communicate in modbus without an RS485 adapter connected to a RaspberryPI, dont remember but that was probably the reason I bought this HAT in the first place..
Now will only be the problem how I safely test the communication without breaking anything in the inverter or compressor..
This moment is stressing me a bit as I dont want many days to go between I solder in the compressor in the refrigerant circuit, leaktest and vacuum it and fill it with the refrigerant. The last step includes running the compressor in a relevant speed.
Now I also got think about that the electronic expansion valve (Carel) is able to connect by modbus too... But it can be another slave in the chain I hope.
Reply 0 0
thiagoralves
Yeah, you will have to test it to be sure. Maybe the easiest (and safest) way to test this would be to buy a cheap USB-RS485 adapter and then connect that to your computer running a Modbus slave simulator software
Reply 1 0
Reply