HSEROUT problem


Closed Thread
Results 1 to 4 of 4

Thread: HSEROUT problem

  1. #1
    Join Date
    Jan 2012
    Posts
    4

    Default HSEROUT problem

    Hi:

    I'm need send some characters in RS485. When I received a string from the master, then send the characters.

    If I received next string:
    02 10 02 cf 00 02 04 00 00 00 00 a9 9b
    (code "hserin 15,PasoSerie,[b0,b1,b2,b3]"
    "hserin 15,PasoSerie,[b4,b5,b6,b7,b8,b9,b10,b11,b12]")
    then I send to the master:
    02 10 02 cf 00 02 70 7c
    (code "hserout [bs0,bs1,bs2,bs3,bs4,bs5,bs6,bs7,10]")
    All is OK.


    But if I received from the master:
    02 03 02 e3 00 01 74 77
    (code "hserin 15,PasoSerie,[b0,b1,b2,b3]")
    then I send to the master:
    02 83 01 70 f0.
    (code "hserout [bs0,bs1,bs2,bs3,bs4,10]")

    The problem: the master dont received this string. The master received another string:
    0f 12 83 01 70 f0 0a

    I'm working with 18F6720 and I dont know how repair this.

    Any suggestion???

  2. #2
    Join Date
    Nov 2008
    Posts
    26

    Default Re: HSEROUT problem

    Hard to say, could you post the entire tx/rx routine and details of hardware.
    I presume your using a max485 or similer as the RS485 hardware interface to the PIC, the first thing that if this is half duplex are you seting the DE line (pin3 on the max485) high during tx ?
    Another note on this is to ensure this remains high for a period of two bytes after the HSEROUT has completed otherwise data still being transmitted bu the UART would be corupted.

    something like:

    HSERIN xx,xxxxx,[xxxxxx] 'recieve data
    DE = 1 'enable 485 tx
    HSEROUT [xxxxxxxx] 'send data
    PAUSE xxx 'wait two bytes
    DE = 0 'disable 485 tx, enable 485 rx

  3. #3
    Join Date
    Jan 2012
    Posts
    4

    Default Re: HSEROUT problem

    Thanks,

    the code used is

    RXTX=1
    pause 2
    CREN=0

    hserout [bs0,bs1,bs2,bs3,bs4,10]

    pause 2
    cren=1
    RXTX=0
    pause 2


    RXTX is DE in MAX485 and CREN is RCSTA1.4.

    I think the problem is in the input, i dont know the lenght of the string the master send me. When he send the string
    02 03 02 e3 00 01 74 77
    I read
    hserin 15,PasoSerie,[b0,b1,b2,b3]
    then I send

    bs0=b0
    bs1=b1+$80
    bs2=$01
    bs3=CRC.lowbyte
    bs4=CRC.highbyte

    RXTX=1
    pause 2
    CREN=0

    hserout [bs0,bs1,bs2,bs3,bs4,10]

    pause 2
    cren=1
    RXTX=0
    pause 2


    The master received next string:
    0f 12 83 01 70 f0 0a

    what's happening??

  4. #4
    Join Date
    Nov 2008
    Posts
    26

    Default Re: HSEROUT problem

    Is there any way you can add in a DEBUG after the "hserin 15,PasoSerie,[b0,b1,b2,b3]"?
    Just to output the raw recieved bytes to monitor in a terminal.

    The other thing that you could do is to clear the RX FIFO before enabling the reciever with "cren = 1". Something like

    temp = RCREG ' clear first byte
    temp = RCREG ' clear second byte
    cren = 1

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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