Shop OBEX P1 Docs P2 Docs Learn Events
RS485 device to Javelin? — Parallax Forums

RS485 device to Javelin?

jmspaggijmspaggi Posts: 629
edited 2009-12-22 15:28 in General Discussion
Hi,

I have a device (Solar panel controller) which is sending status every seconds on a RS-485 bus that I would like to read from the Javelin.

Is there an easy way to do that? Or will I have to by a 232 <-> 485 converter to connect between the 2?

I already have some components like a MAX232 and MAX485 but I don't really know how to use them [noparse]:([/noparse]

Can anyone help me with that?

Thanks,

Jean-Marc

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-12-20 15:07
    You need a rs485 driver chip like MAX485 or MAX487 because the javelin
    pins don't have the drive capacity.

    Attached are my Uart485 class that extends the Uart class.
    And UartTools class to provide parity if you need it.
    Also my adapted Uart class.
    If you use the Uart class that came with the IDE, rename it to Uart_org.java
    Then download attachements to folder ...\lib\stamp\core

    The file Uart485.java has comments how to connect the driver chip.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2009-12-20 15:36
    Awesome! Thanks a lot Peter.

    I never tought it's so simple.

    I already have a MAX485. So I will try today.

    On MAX side, where should DE be connected? Is it with /RE and rwPin?

    Also, since I also need to read on the RS485, do you think I can get rid of rwPin, connect /RE to DE to the ground, and simply use DI and RO with dqPin? If so, I will try to to a Uart485RO.java...

    Thanks again for you assistance!

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-12-20 16:10
    Yes, DE connects directly to /RE
    You need rwPin to switch between transmit and receive

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2009-12-22 13:12
    Hi Peter,

    I tried to do a ReadOnly version based on the version you send, but I ended with pretty empty.

    package stamp.core;
    
    /**
     * 
     * This class implement a ReadOnly version of UART485.
     * 
     * The half duplex RS485 chip is a Maxim MAX487 or compatible (MAX485), or a chip
     * wired to comply to this class. Here is the required wiring:
     *
     *                            MAX487 or compatible
     *   JAVELIN             +-------------------------------+
     *   ------+  +----------o /RE (receiver enable)         |
     *         |  |  +-[noparse][[/noparse]1K]--o RO  (receiver output)       A o------
     *         |  |  |       |                               |    RS485
     *   dqPin o-----+       o DI  (transmitter input)     B o------
     *         |  +----------o DE  (transmitter enable)      |
     *   ------+             +-------------------------------+
     *
     *   dqPin is a bidirectional datapin to receive and transmit data.
     *
     * Date 04-16-2009 Added constructor without parity parameter
     * Date 10-22-2004
     * Author: Peter Verkaik (peterverkaik@boselectro.nl)
     * 
     * Date 22-12-2009 Create a ReadOnly version from the initial one.
     * Authier: Jean-Marc Spaggiari (Jean-Marc@Spaggiari.org)
     */
    
    public class Uart485RO extends Uart {
    
      /**
       * Creates and initialises a new RS485 Uart for bidirectional half duplex communication
       * using a single transmit/receive enable signal. The constructor calls the
       * <code>start()</code> method so the RS485 Uart will begin working immediately.
       * The uart starts in receive mode.
       * This constructor uses the uart VP without handshake.
       *
       * @param parity   UartTools.NONE, UartTools.ODD or UartTools.EVEN
       * @param dqPin    The Javelin Stamp I/O pin to use for sending and receiving data.
       * @param dqInvert Whether the data should be inverted or not. Valid options are
       *                 <code>Uart.invert</code> and <code>Uart.dontInvert</code>.
       *                 For the MAX487, use dontInvert.
       * @param baudRate The baud rate to use.
       * @param stopBits The number of stop bits to use. Valid values are between
       *                 <code>Uart.stop1</code> and <code>Uart.stop8</code>.
       */
      public Uart485RO(int parity, int dqPin, boolean dqInvert, int baudRate, int stopBits) 
      {
        super(Uart.dirReceive,parity,dqPin,dqInvert,0,dontInvert,baudRate,stopBits);
      }
    
      /**
       * Creates and initialises a new RS485 Uart for bidirectional half duplex communication
       * using a single transmit/receive enable signal. The constructor calls the
       * <code>start()</code> method so the RS485 Uart will begin working immediately.
       * The uart starts in receive mode.
       * This constructor uses the uart VP without handshake.
       *
       * @param dqPin    The Javelin Stamp I/O pin to use for sending and receiving data.
       * @param dqInvert Whether the data should be inverted or not. Valid options are
       *                 <code>Uart.invert</code> and <code>Uart.dontInvert</code>.
       *                 For the MAX487, use dontInvert.
       * @param baudRate The baud rate to use.
       * @param stopBits The number of stop bits to use. Valid values are between
       *                 <code>Uart.stop1</code> and <code>Uart.stop8</code>.
       */
      public Uart485RO(int dqPin, boolean dqInvert, int baudRate, int stopBits) 
      {
        super(Uart.dirReceive,dqPin,dqInvert,0,dontInvert,baudRate,stopBits);
      }
    }
    
    



    I removed everything related to the direction and the RW pin.

    Look like if we want to do a RS485 ReadOnly device, we just need to use the correct wire and the Uart class directly, correct? So a Uart485RO class is useless...

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-12-22 13:21
    For readonly, tie DE and /RE to GND,
    connect RO to dqPin, you can leave DI disconnected.
    Then you can simply use a receive Uart using dqPin, as you said.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2009-12-22 13:24
    Hi Peter,

    Thanks for your prompt reply.

    If I don't connect dqPin anymore to DI, should I still use the 1K resistor to RO?

    Thanks,

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-12-22 15:05
    The 1k protects the javelin I/O pin in case
    you make that pin an output by mistake.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2009-12-22 15:28
    So I will keep it [noparse];)[/noparse]

    Perfect.

    Thanks a lot!

    JM
Sign In or Register to comment.