Author Topic: Arduino & RS485  (Read 3482 times)

rexlee

  • Newbie
  • *
  • Posts: 3
    • View Profile
Arduino & RS485
« on: April 25, 2015, 11:58:24 PM »
I have an Arduino master & three slaves using RS485 and the Arduino libraries & that works fine/
I want to replace the Master with AdvancedHMI.  I have a USB dongle connected to the RS485 interface and am using RTS to control the RS485 transceiver, but it seems to me that AdvancedHMI does not support RTS ???????
I thought that there might be a property for RTS control but,  there is none.
How can I get AdvancedHMI control the RS495 transceiver.
Thanks in advance for ideas & help.
Lee

neptun2002

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Arduino & RS485
« Reply #1 on: April 26, 2015, 02:52:36 AM »
Hi you have to make some change in the library by your self for arduino-modbus-slave library in the fowling link I added the control pin for the main function to become like this 

//void modbusSlave::run(void)
void modbusSlave::run(int SSerialTxControlPin)

so now whenever you want use the RS485 you have to control it the code I made is like this


//****************************************************************************************

#define SSerialTxControl 2   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW

      digitalWrite(SSerialTxControlPin, RS485Transmit);  // Enable RS485 Transmit
      
      
            for(i = 0 ; i < _len ; i++)
               {
               Serial1.write(_msg);
               Serial.write(_msg);
               }
      delay(10);
      digitalWrite(SSerialTxControlPin, RS485Receive);  // Disable RS485 Transmit             
//****************************************************************************************


https://code.google.com/p/arduino-modbus-slave/

rexlee

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Arduino & RS485
« Reply #2 on: April 27, 2015, 01:27:17 AM »
Thanks neptun 2002.
Th eproblem is not with the slavesWhen they reply, they assert a pin, which enables their RS485 transceiver.
The problem is the transceiver associated with the Master Ie. the PC
The PC uses a USB to TTL convertor which then connects to a TTL to RS485. convertor.
The RS485 data transceiver needs to get a TX enable signal from the RTS line to enable transmission.

With other VB applications where I have used a COM control, there was a property RTS ON TX, but I do not see such a property on the AdvancedHMI control and the RTS is definitively not being asserted when the AdvancedHNI application polls the slaves.

A possible work around at this stage appears to be to wire-OR the slaves RTS /transmit enables together & let the complement of that drive the transmit enable of the master.   However, that is not elegant and requires additional wires & logic, when the solution lies at the master end to implement RTS.
Have I got how AdvancedHMI works wrong?? :-[

Lee

PS My application is a two marine engine monitoring system.  (Main engine & generator set)


neptun2002

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: Arduino & RS485
« Reply #3 on: April 27, 2015, 03:02:53 AM »
Hi rexlee in fact I tested the AdvancedHmi rtu driver with more than three USB to RS485 and I did not have this problem it works great may be the usb driver deal with this problem try this setup I am sure it will work with you

thanks

rexlee

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Arduino & RS485
« Reply #4 on: April 27, 2015, 05:00:44 AM »
Ah..OK,
You are saying that your dongle is a fully fledged USB-RS485, whereas mine is one that I cobbled up with the modules that I had!  Good point!
I will order some USB-RS485 dongles & keep my fingers cross that all the magic happens in the module.
This will take a week or two as they come from China & I will be on the road for two weeks heading for my two month fishing holiday in Far North Oz.
Thanks,
Lee