Rs485 Using Hserin/hserout


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Thank you very much Mister_e!

    I have implement it

    <hr>
    Code of My Master PIC
    <br>
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2296&stc=1&d=120129233 2" border="1">
    <hr>
    Code of My Slave PIC
    <br>
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2297&stc=1&d=120129234 2" border="1">



    But it still only returns:
    <b>
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    </b>
    Attached Images Attached Images   

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what's your expected baudrate? I feel 2400 bauds right?

    so you should use...
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 25  ' 2400 Baud @ 4MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    OR
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 103  ' 2400 Baud @ 4MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Unless your current USART setting show 600 baud.. and i'm not sure how god/bad it may works with your current hardware.

    I would tent to use Usart interrupt for that.. but you can still remove the TimeOut to see what happen. Your code work as design so far.

    Still looking...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Try adding "Fail-Safe" resistors to the RS-485 buss.

    2.2k from A to VDD
    2.2k from B to gnd

    When both ends are in receive mode, the buss is left floating.

    If you're going to have multiple slaves on long distance wires, you may also need 4 schottky diodes on each device.
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Thank you very much Mister_e, I have changed it to the second option, but still receives the :
    <b>
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    WAITING FOR REPLY..
    </b>


    Darrel, the 2.2k from A to VDD and 2.2k from B to gnd, must I put them on the Master and all the Slaves?

    I will have long distance cables and multiple slaves.
    Where will I put the diodes?

    Thank you
    Koossa

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The resistors and diodes should be on each device.

    I like the Schottky-Diode Termination method because it allows you the have a "Star" configuration on the 485 buss, and it uses less power than other methods.

    Other types of termination require the devices to be in a line with a single termination at the farthest end. This is not always practical, and invariably the farthest end device gets disconnected somewhere along the way, and there goes your termination. Unless someone remembers to terminate the next farthest device. (never happens)

    See figure 6 in this page for the diodes.
    http://www.maxim-ic.com/appnotes.cfm/an_pk/1090
    <br>
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Darrel, thank you very much!!!

    I have updated my Schematic, could you please confirm that I understand it correctly (see attachment)?

    Koossa
    Attached Images Attached Images

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Thumbs up

    Yup!

    That looks good.
    <br>
    DT

Similar Threads

  1. RS485 splitter
    By The Master in forum Off Topic
    Replies: 0
    Last Post: - 30th August 2009, 06:04
  2. RS485 Vs Wireless (TWS-434A)
    By koossa in forum Off Topic
    Replies: 3
    Last Post: - 11th April 2009, 12:40
  3. Using 16f676 with comms
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 28th October 2005, 20:01
  4. RS485 - ibutton network
    By ccsparky in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th June 2005, 21:48
  5. RS485 Extender
    By SergioRM in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th December 2004, 00:09

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts