Rs485 Using Hserin/hserout


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Background Question

    Hi Koossa,
    Background Question:
    How much distance between master and slave? I am thinking maybe baud rate is too high due to line capacitance, I just had that problem with an ethernet connection, couldn't use 100 had to tell computer to use 10mbs.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Joe, the distance between my Master and slave is only about 1.5 meters.

    <hr>
    Darrel

    When I remove the handshacking it is working!!

    <b>
    WAITING FOR REPLY..
    REC:1
    WAITING FOR REPLY..
    REC:1
    WAITING FOR REPLY..
    REC:1
    WAITING FOR REPLY..
    REC:1
    WAITING FOR REPLY..
    REC:1
    WAITING FOR REPLY..
    REC:1
    WAITING FOR REPLY..
    REC:1
    </b>

    Do I need to play arround with "pause"?

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    See Posts #2 & #5.
    Failing that, post the program as it sits now...

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Skimask

    Thank you for your reply!

    Whith the following code I only get..
    <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>


    SLAVE
    <hr>
    <CODE>
    &nbsp;Include "Modedefs.bas"

    &nbsp;DEFINE&nbsp;&nbsp; OSC 4

    &nbsp;DE_OR_RE&nbsp;&nbsp;VAR PORTC.5&nbsp;&nbsp; ' DE and RE Pin of SN75176
    &nbsp;LEDPIN&nbsp;&nbsp; VAR PORTD.2&nbsp;&nbsp; ' LED to confirm PIC is running
    &nbsp;DATARECEIVED&nbsp;VAR BYTE
    &nbsp;
    &nbsp;'======== HSEROUT, HSERIN SETTINGS ==========
    &nbsp;DEFINE HSER_RCSTA 90h
    &nbsp;define HSER_TXSTA 24h
    &nbsp;define HSER_SPBRG 103
    &nbsp;DEFINE HSER_CLROERR 1
    &nbsp;RCIF&nbsp;&nbsp;VAR PIR1.5
    &nbsp;TXIF&nbsp;&nbsp;VAR PIR1.4

    &nbsp;ADCON1 = 7
    &nbsp;TRISC = %10000000
    &nbsp;
    &nbsp;pause 200
    &nbsp;HIGH LEDPIN
    Main:
    &nbsp;LOW DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;' Make ready for RX
    &nbsp;PAUSE 4
    &nbsp;hserin 100,Main,[WAIT ("S"),DATARECEIVED] ' Looking for "S0"
    &nbsp;IF DATARECEIVED = "0" THEN
    &nbsp;&nbsp;&nbsp;&nbsp;HIGH DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Make ready for RX
    &nbsp;&nbsp;&nbsp;&nbsp;PAUSE 4
    &nbsp;&nbsp;&nbsp;&nbsp;HSEROUT ["R1"]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Send R1
    &nbsp;ENDIF
    &nbsp;GOTO MAIN

    END
    </CODE>
    <hr>

    MASTER
    <hr>
    <CODE>
    &nbsp;Include "Modedefs.bas"
    &nbsp;&nbsp;
    &nbsp;DEFINE&nbsp;&nbsp; OSC 4

    &nbsp;DE_OR_RE&nbsp;&nbsp;VAR PORTC.5&nbsp;&nbsp; ' DE and RE Pin of SN75176
    &nbsp;RS232_DEBUG_PIN VAR PORTB.5&nbsp;&nbsp; ' Debugging to PC
    &nbsp;LEDPIN&nbsp;&nbsp; VAR PORTD.2&nbsp;&nbsp; ' LED to confirm PIC is running
    &nbsp;DATARECEIVED&nbsp;VAR BYTE

    &nbsp;'======== HSEROUT, HSERIN SETTINGS ==========&nbsp;
    &nbsp;DEFINE HSER_RCSTA 90h
    &nbsp;define HSER_TXSTA 24h
    &nbsp;define HSER_SPBRG 103
    &nbsp;DEFINE HSER_CLROERR 1
    &nbsp;RCIF&nbsp;&nbsp;VAR PIR1.5
    &nbsp;TXIF&nbsp;&nbsp;VAR PIR1.4
    &nbsp;
    &nbsp;ADCON1 = 7
    &nbsp;TRISC = %10000000

    &nbsp;PAUSE 200
    &nbsp;HIGH LEDPIN
    &nbsp;
    Main:
    &nbsp;HIGH DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; ' Make ready for TX
    &nbsp;PAUSE 4
    &nbsp;HSEROUT ["S0"]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; ' Send "S0"
    &nbsp;LOW DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;' Make ready for RX
    &nbsp;PAUSE 4
    &nbsp;SEROUT RS232_DEBUG_PIN,N2400,["WAITING FOR REPLY..", 13, 10] ' DEBUG TO PC
    &nbsp;hserin 100,Main,[WAIT ("R"),DATARECEIVED]
    &nbsp;SEROUT RS232_DEBUG_PIN,N2400,["REC:",DATARECEIVED, 13, 10] ' DEBUG TO PC
    GOTO Main
    END
    </CODE>
    <hr>


    Any idea what I am doing wrong?

    Thank you very much!!!!
    Koossa

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    It takes at least 87.5ms for each of those SEROUT debug statements to execute at 2400 baud. My guess is that both sides are getting sync'd up into not receiving each others inputs and they both end up missing each others outputs.
    How about getting rid of them and try to use LEDs to see if either program is getting what it should? Maybe use a couple of switches on one, and LEDs on the other, and get one PIC to follow the other PIC.

    Failing that, how about this:

    SLAVE
    ----------------------------------------------------------
    Include "Modedefs.bas"
    DEFINE OSC 4
    DE_OR_RE VAR PORTC.5 ' DE and RE Pin of SN75176
    LEDPIN VAR PORTD.2 ' LED to confirm PIC is running
    DATARECEIVED VAR BYTE
    '======== HSEROUT, HSERIN SETTINGS ==========
    DEFINE HSER_RCSTA 90h
    define HSER_TXSTA 24h
    define HSER_SPBRG 103
    DEFINE HSER_CLROERR 1
    RCIF VAR PIR1.5:TXIF VAR PIR1.4:ADCON1 = 7:TRISC = %10000000
    pause 200:HIGH LEDPIN
    Main:
    hserin 10,MAIN,[WAIT ("S"),DATARECEIVED] ' Looking for "S0"
    IF DATARECEIVED = "0" THEN
    HSEROUT ["R1"] ' Send R1
    else
    hserout ["RZ"] ' Send something to signify SOMETHING received
    ENDIF
    GOTO MAIN
    END
    --------------------------------------------------------------------------------

    MASTER
    --------------------------------------------------------------------------------
    Include "Modedefs.bas"
    DEFINE OSC 4
    DE_OR_RE VAR PORTC.5 ' DE and RE Pin of SN75176
    RS232_DEBUG_PIN VAR PORTB.5 ' Debugging to PC
    LEDPIN VAR PORTD.2 ' LED to confirm PIC is running
    DATARECEIVED VAR BYTE
    '======== HSEROUT, HSERIN SETTINGS ==========
    DEFINE HSER_RCSTA 90h
    define HSER_TXSTA 24h
    define HSER_SPBRG 103
    DEFINE HSER_CLROERR 1
    RCIF VAR PIR1.5:TXIF VAR PIR1.4:ADCON1 = 7:TRISC = %10000000
    PAUSE 200:HIGH LEDPIN
    Main:
    HSEROUT ["S0"] ' Send "S0"
    SEROUT RS232_DEBUG_PIN,N2400,["WAITING FOR REPLY..", 13, 10] ' DEBUG TO PC
    hserin 100,Main,[WAIT ("R"),DATARECEIVED]
    SEROUT RS232_DEBUG_PIN,N2400,["REC:",DATARECEIVED, 13, 10] ' DEBUG TO PC
    GOTO Main
    END

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