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

    Don't know if I understand you correctly, but here is my new code

    MASTER PIC
    <HR>
    <p>&nbsp;&nbsp; Include &quot;Modedefs.bas&quot;&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; DEFINE OSC 4&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; PORTC.5&nbsp;&nbsp;&nbsp;&nbsp; ' DE and RE Pin of SN75176&nbsp;&nbsp;
    &nbsp;&nbsp; RS232_DEBUG_PIN&nbsp;&nbsp;&nbsp;&nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; PORTB.5&nbsp;&nbsp;&nbsp;&nbsp; ' Debugging to PC
    &nbsp;&nbsp; LEDPIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; PORTD.2&nbsp;&nbsp;&nbsp;&nbsp;' LED to confirm PIC is running&nbsp;&nbsp;
    &nbsp;&nbsp; DATARECEIVED&nbsp;&nbsp;&nbsp;&nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; BYTE&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; '======== HSEROUT, HSERIN SETTINGS ========== &nbsp;&nbsp;
    &nbsp;&nbsp; DEFINE&nbsp;&nbsp;&nbsp;&nbsp; HSER_RCSTA&nbsp;&nbsp;&nbsp; 90h&nbsp;&nbsp;
    &nbsp;&nbsp; define&nbsp;&nbsp;&nbsp;&nbsp; HSER_TXSTA&nbsp;&nbsp;&nbsp; 20h&nbsp;&nbsp;
    &nbsp;&nbsp; define&nbsp;&nbsp;&nbsp;&nbsp; HSER_SPBRG&nbsp;&nbsp;&nbsp; 103&nbsp;&nbsp;
    &nbsp;&nbsp; DEFINE&nbsp;&nbsp;&nbsp;&nbsp; HSER_CLOERR&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;
    &nbsp;&nbsp; RCIF&nbsp;&nbsp;&nbsp;&nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; PIR1.5&nbsp;&nbsp;
    &nbsp;&nbsp; TXIF&nbsp;&nbsp;&nbsp;&nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; PIR1.4&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; ADCON1 = 7&nbsp;&nbsp;
    &nbsp;&nbsp; TRISC = %10000000&nbsp;&nbsp;
    &nbsp;&nbsp;
    Main:&nbsp;&nbsp;
    &nbsp;&nbsp; HIGH LEDPIN ' Indicate PIC is running&nbsp;&nbsp;
    &nbsp;&nbsp; HIGH DE_OR_RE ' Make ready for TX&nbsp;&nbsp;
    &nbsp;&nbsp; PAUSE 4&nbsp;&nbsp;
    &nbsp;&nbsp; HSEROUT [&quot;S0&quot;] ' Send &quot;S0&quot;&nbsp;&nbsp;
    &nbsp;&nbsp; LOW LEDPIN&nbsp;&nbsp;
    &nbsp;&nbsp; LOW DE_OR_RE ' Make ready for RX&nbsp;&nbsp;
    &nbsp;&nbsp; PAUSE 4&nbsp;&nbsp;
    &nbsp;&nbsp; SEROUT RS232_DEBUG_PIN,N2400,[&quot;WAITING FOR REPLY..&quot;, 13, 10] ' DEBUG TO PC&nbsp;&nbsp;
    &nbsp;&nbsp; if RCIF then&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hserin 100,Main,[WAIT (&quot;R&quot,DATARECEIVED]&nbsp;&nbsp;
    &nbsp;&nbsp; ENDIF&nbsp;&nbsp;
    &nbsp;&nbsp; SEROUT RS232_DEBUG_PIN,N2400,[&quot;REC:&quot;,DATARECEIVED, 13, 10] 'DEBUG TO PC&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; GOTO Main&nbsp;&nbsp;
    &nbsp;&nbsp;
    END</p>

    <HR>




    SLAVE PIC
    <hr>
    <p>&nbsp;&nbsp; Include &quot;Modedefs.bas&quot;&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; DEFINE OSC 4&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; DE_OR_RE&nbsp;&nbsp;&nbsp;&nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; PORTC.5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' DE and RE Pin of SN75176&nbsp;&nbsp;
    &nbsp;&nbsp; LEDPIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; PORTD.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' LED to confirm PIC is running&nbsp;&nbsp;
    &nbsp;&nbsp; DATARECEIVED&nbsp; VAR&nbsp;&nbsp;&nbsp;&nbsp; BYTE&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; '======== HSEROUT, HSERIN SETTINGS ==========&nbsp;&nbsp;
    &nbsp;&nbsp; DEFINE HSER_RCSTA 90h&nbsp;&nbsp;
    &nbsp;&nbsp; define HSER_TXSTA 20h&nbsp;&nbsp;
    &nbsp;&nbsp; define HSER_SPBRG 103&nbsp;&nbsp;
    &nbsp;&nbsp; DEFINE HSER_CLOERR 1&nbsp;&nbsp;
    &nbsp;&nbsp; RCIF VAR PIR1.5&nbsp;&nbsp;
    &nbsp;&nbsp; TXIF VAR PIR1.4&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; ADCON1 = 7&nbsp;&nbsp;
    &nbsp;&nbsp; TRISC = %10000000&nbsp;&nbsp;
    &nbsp;&nbsp;
    Main:&nbsp;&nbsp;
    &nbsp;&nbsp;
    &nbsp;&nbsp; HIGH LEDPIN ' Indicate PIC is running&nbsp;&nbsp;
    &nbsp;&nbsp; LOW DE_OR_RE ' Make ready for RX&nbsp;&nbsp;
    &nbsp;&nbsp; PAUSE 4 &nbsp;&nbsp;
    &nbsp;&nbsp; LOW LEDPIN&nbsp;&nbsp;
    &nbsp;&nbsp; if RCIF then&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hserin 100,Main,[WAIT (&quot;S&quot,DATARECEIVED] ' Looking for &quot;S0&quot;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IF DATARECEIVED = &quot;0&quot; THEN&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; HIGH DE_OR_RE ' Make ready for RX&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; PAUSE 4&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp; HSEROUT [&quot;R1&quot;] ' Send R1
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ENDIF&nbsp;&nbsp;
    &nbsp;&nbsp; endif&nbsp;&nbsp;
    &nbsp;&nbsp; GOTO MAIN&nbsp;&nbsp;
    &nbsp;&nbsp;
    END</p>
    <hr>


    As soon as I connect the Master pic to the power I get the following, does not matter if the Slave pic is running or not, it return the same data.

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

    Thank you
    Koossa

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    I think you've got the idea...but one other thing I just thought about...

    You're checking RCIF in the code. If you're checking RCIF, that means there's already a byte in the receive buffer. HSERIN probably waits for the next byte to come along (basically ignoring what's already in the buffer). If you're already WAITing for a specific character, then why also wait for a flag in hardware? Also, you can make use of the TIMEOUT in the SERIN/HSERIN to keep your code from getting stuck.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thank you, I will remove the RCIF and see what happens.

    There is a 100ms Timeout in my code.

    Koossa

  4. #4


    Did you find this post helpful? Yes | No

    Default

    I now get the following on the PC Side, so I assume it does not receive the "R"
    (<b>hserin 100,Main,[WAIT ("R"),DATARECEIVED]</b>) and reaches the Timeout of 100 milliseconds?


    <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..
    </b>


    Any ideas?

    Thank you
    Koossa

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


    Did you find this post helpful? Yes | No

    Default

    Yup that's it!

    PS: careful with your DEFINEs. DEFINE HSER_CLOERR 1 have to be DEFINE HSER_CLROERR 1
    Steve

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

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