Shop OBEX P1 Docs P2 Docs Learn Events
Help with RS-485 interface — Parallax Forums

Help with RS-485 interface

mynet43mynet43 Posts: 644
edited 2011-06-08 08:30 in Propeller 1
I have a Prop circuit using the MAX485 chip. It's used to connect to a single slave device using only two lines, RX-, RX+ (and GND).

My question is the control of the Send/Receive line on the chip. Since I'm the master, I need to control this.

Does someone have experience with this circuit, to point to a good driver or other source for this application?

I'd prefer to use something like pcFullDuplexSerial4FC, so I can service more than one port with a single cog.

Thank you for your help.

Jim

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-06-07 07:45
    Jim,

    While I've used RS-485 a little myself, I don't think I know enough to give you any useful information.

    I know JonnyMac has done some RS-485 stuff. I think there is a Spin Zone article about it (which JonnyMac wrote). I just found the title Do It Up With DMX (N&V Nov. '09). It's nvp3.pdf in the Propeller download section.

    pcFullDuplex4FC has been a life saver for many people. I like to think I improved a good thing by increasing the rx buffer from 64 byte to 128 bytes with only adding a few longs to the size of the code. You can find the 128 byte rx buffer version here. (It has 128 added to the end of the name.)

    I have some of my other variations of pcFullDuplex4FC on the same thread.

    Duane
  • mynet43mynet43 Posts: 644
    edited 2011-06-07 09:37
    Duane,

    Thanks for the reference, I'll take a look.

    Interesting about pcFullDuplex4FC. I think the I/O from the prop may be the same as RS-232.

    See the attached schematic. The RS232 and RS485 look the same to the Prop except for the snd/rcv line on the 485.

    Does the driver have some kind of a control signal, like RTS or something that could be used to toggle the line for send/receive?

    That would be a lifesaver...

    Thanks for the help.

    Jim
  • JonnyMacJonnyMac Posts: 9,175
    edited 2011-06-07 09:49
    I've done a lot of RS-485. If you're only ever going to be the master then you can tie the TX Enable (DE) pin high. I've attached the circuit that I tend to use in my half-duplex apps; the TX Enable and RX Enable\ pins are pulled low to default to RX mode. For TX apps the control pin is made an output and high. Note that if you're going to do half-duplex RX and TX then you will need to adjust the driver. The TX Enable pin needs about 10us to settle before you start transmitting bytes, and you must make sure that the final stop bit period has expired before you disable the TX Enable to return to RX mode. This are little things that can bite you using half-duplex RS-485.
    771 x 398 - 76K
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-06-07 11:12
    Duane,
    mynet43 wrote: »
    Does the driver have some kind of a control signal, like RTS or something that could be used to toggle the line for send/receive?

    None of the drivers I'm aware take care of the /RE line for you.

    It wouldn't be too hard to add something to the spin portion of the driver to toggle the /RE line when the str or tx function is called. You could add a method to define a port as RS-485 and tell which pin to use as the /RE line.

    Using the four port drivers can limit your baud rate. I understand the half duplex drivers can go faster.

    As Jon said, you want to make sure there is a 10us delay, after setting the /RE line high, before you start transmitting.

    As Jon pointed out in his article, you can save some money by using the 5V version of the RS-485 chip. The 5V version works fine with the Prop as long as you follow Jon's schematic.

    Speaking of which; Jon, I noticed a couple of changes in the schematic you just posted from the one in the Nuts & Volts article.

    nvp3_RS485.PNG


    I figure the newest version is preferable?

    Duane
    748 x 429 - 81K
  • JonnyMacJonnyMac Posts: 9,175
    edited 2011-06-07 12:35
    I figure the newest version is preferable?

    The differences in resistor values are minor and both versions work -- I just like the second version as the values seem to make more sense (i.e., we're all used to 10K pull-ups/pull-downs). That said, the earlier version simplifies purchasing.
  • mynet43mynet43 Posts: 644
    edited 2011-06-07 18:59
    Thanks for the great info. It really helps since I haven't used 485 before.

    A couple of questions about the schematic.
    1. Are the pull-up and pull-down resistors on RO and DE needed if I'm controlling them from the Prop?
    2. Is the 120 ohm resistor needed if I use twisted pair cable?

    Regarding the driver. I like your idea of adding a control line to the output routines like tx and str. This way I can leave it in receive mode until I need to send something. Since I'm the master, it seems like this should work.

    @ Jon, which driver do you use, and how are your messages terminated.

    Thank you for the help.

    Jim
  • JonnyMacJonnyMac Posts: 9,175
    edited 2011-06-07 20:47
    Don't be cheap -- resistors cost next to nothing and will keep those pins in the proper state when the Propeller is in reset and all pins are in input state. You need the 120 ohm resistor on the ends of the line (at the transmitter and at the last receiver).

    My projects, thus far, have been half-duplex one-way, or full-duplex with a full-duplex chip (MAX489). I'm working on a driver that will allow for half-duplex RS-485 with the circuit posted here; I'll put it in ObEx when it's done and working.
  • mynet43mynet43 Posts: 644
    edited 2011-06-07 20:54
    Hi Jon,

    Good advice. I'll put them in. I'm still learning this circuit.

    I'll always be in half duplex to a single device, since there are only 3 wires to connect to at the other end, including GND.

    Do you have an idea when your driver will be ready?

    Thanks for the help.

    Jim
  • JonnyMacJonnyMac Posts: 9,175
    edited 2011-06-08 08:03
    To be clear, you need half-duplex TX and RX, right? I've got a (Propeller-based) product to finish up and then I will get back to the driver. The product I'm working on includes a full-duplex part but I'm writing the half-duplex library for it, anyway.
  • mynet43mynet43 Posts: 644
    edited 2011-06-08 08:30
    Hi Jon,

    Yes, half duplex Rx, Tx, with me as the master. I'll only be working at 9600 baud for this connection. It's to an AC motor control box.

    It uses the Modbus comm protocol in the Remote Terminal Unit (RTU) transmission mode.

    Thanks again,

    Jim
Sign In or Register to comment.