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

    Could this happen when the 2 pics are on seperate power supplies?

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by koossa View Post
    Could this happen when the 2 pics are on seperate power supplies?
    Might have something to do with all of those pauses you've got sprinkled in the code. If the pauses don't line up right (the moon, saturn, mars, etc), one part of the project, either the master or the slave, misses a reception at one time or another, and/or gets caught in the middle of one or the other...basically a sync'ing issue.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Hi Skimask

    Must I remove all the pauses?
    I am working on 2400 Baud and want to give enough time to transmit the data.

    Thank you
    Koossa

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by koossa View Post
    Hi Skimask
    Must I remove all the pauses?
    I am working on 2400 Baud and want to give enough time to transmit the data.
    Thank you
    Koossa
    That's just it, you're giving it enough time to TX the data, but in the process of Pausing for 100ms afterwards, you might've missed 200-ish bits of serial data. The receive buffer is only 2 bytes deep (1 if you want be conservative). I'd say pause for 1 byte time, 4ms (2400 baud = .416ms/bit = 4.16ms/byte) instead of 100ms.

    The SERIN and SEROUT commands won't let the program continue until they're finished transmitting or receiving.
    HSERIN/HSEROUT, not sure about them, as I generally access the serial port registers directly rather than using the commands.
    I would assume that they would act the same as SERIN and SEROUT for continuity purposes, but, I would hope that they would be 'non-blocking' commands (unless WAIT is used with HSERIN of course).

  5. #5


    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

  6. #6
    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.

  7. #7


    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

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