16f887 and hserin/out


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1

    Default 16f887 and hserin/out

    Hi All

    Just wondering if anyone has encountered weird behaviour with HSERIN/OUT using a 16F887 at all ?

    I was using the 16F887 (hserout) as a receiver for data sent from a 18F4520 (hserin) as a receiver.

    When I switch the roles so that the 16F887 is the transmitter and the 184520 is the receiver ... I either get mismatched data or no data at all !

    Is it possible I have trhe wrong config settings for the registers on either side at all ?
    for the 16F887 I have this
    Code:
     'Set comparators off
    CM1CON0 = %00000000
    CM2CON0 = %00000000
    
    OSCCON = %01110001          'Int CLK 8MHz
    ANSEL = %00000000           'All digital
    OPTION_REG.7 = 0            'Weak pull-ups enabled
    
    DEFINE OSC 8                '8MHz
    'TRIS statements
            TRISA  = %00000000 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10100000 'PORTC.7 and C.5 are input
            TRISD = %00000000
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0
    and for the 18F4520 I have this
    Code:
     OSCCON = $70            'Int CLK 8MHz
            OSCTUNE.6 = 1           'PLL 4x
            ADCON1= %00001111       '$0F = disable A/D converter
            cmcon   =   7 
            INTCON2.7 = 0     'switch pull-ups ON
    '
            DEFINE OSC 32            '4x 8MHz
            TRISA  = %00000000 
            TRISB = %11111111  'for 4x4 keypad all input
            TRISC = %10010000 'PORTC.7 and C.4 are input
            TRISD = %00000000 'all output
            TRISE.0 = 0
            TRISE.1 = 0
            TRISE.2 = 0

    Any suggestion would be appreciated.

    Kind regards
    Dennis
    Last edited by Dennis; - 18th December 2009 at 01:08.

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


    Did you find this post helpful? Yes | No

    Default Cats !

    Quote Originally Posted by Dennis View Post
    Hi All

    Just wondering if anyone has encountered weird behaviour with HSERIN/OUT using a 16F887 at all ?

    I was using the 16F887 (hserout) as a receiver for data sent from a 18F4520 (hserin) as a receiver.

    When I switch the roles so that the 16F887 is the transmitter and the 184520 is the receiver ... I either get mismatched data or no data at all !

    Any suggestion would be appreciated.

    Kind regards
    Dennis
    Hi Dennis,
    The pic 16f887 and the pic18F4520 are different breeds of Cats, which is to say they require different configs and register settings. It may be you are experiencing ports that are not in full digital mode on the chips, esp. the 18F part which would explain the complete non op situation. as far as I know the setup numbers in the hserin vs hserout are the same within a given PIC and May in fact be the same across the line. Remember too that hserin/out sends data TRUE and never INVERTED and as such idles in a high state, which is to say it very much would like a pullup resistor on the line, that said, you May have inadvertanly set code to enable pullups on one of your chips, so make sure you have a pullup.
    EDIT: you edited your post while I was typing, and I was using both fingers too
    Last edited by Archangel; - 18th December 2009 at 01:19.
    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.

  3. #3


    Did you find this post helpful? Yes | No

    Default thanks Joe

    Thanks Joe :-)

    So a quick fix would be to disable pull-ups on the receiver PIC 16F887 ?
    Fo rthe 18F4520 I have an LCD on PORTA and a 4x4 keypad on PORTB

    FOR the 16F887 I have the following setting for HSERIN/OUT
    Code:
     DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
        DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
        DEFINE HSER_SPBRG 51  ' 2400 Baud @ 8MHz, 0.17%
        DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    and for the 184520
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 207 ' 2400 Baud @ 32MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Kind regards
    Dennis

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


    Did you find this post helpful? Yes | No

    Default

    Hi Dennis,
    The PIC18F4520 has more registers to play . . .
    SSPCON1.5 = 0
    Will disable the synchronous Serial port and make it STD I/O. I am still looking for other issues . . .
    Looks like on POR is should come up as zero but who knows?
    Try RCSTA = %10010000
    I am a little fuzzy on bit 5 though, read section 18 in the data sheet and it also says:
    The pins of the Enhanced USART are multiplexed
    with PORTC. In order to configure RC6/TX/CK and
    RC7/RX/DT as a USART:
    • bit SPEN (RCSTA<7>) must be set (= 1)
    • bit TRISC<7> must be set (= 1)
    • bit TRISC<6> must be set (= 1)
    The operation of the Enhanced USART module is
    controlled through three registers:
    • Transmit Status and Control (TXSTA)
    • Receive Status and Control (RCSTA)
    • Baud Rate Control (BAUDCON)
    These are detailed on the following pages in
    Register 18-1, Register 18-2 and Register 18-3,
    respectively.
    Note: The EUSART control will automatically
    reconfigure the pin from input to output as
    needed.
    Last edited by Archangel; - 18th December 2009 at 01:48.
    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.

  5. #5


    Did you find this post helpful? Yes | No

    Default thanks again Joe

    Hi Joe :-)
    How are you ?

    Just wondering whether my problem lies at 18F4520 or 16F887 !
    You see when the 18F4520 was a set as the receiver and the 16F887 as a transmitter,
    I would do an HSERIN to catch the data from the transmitter PIC and then an HSEROUT directly after to send the data to the PC comport ...All worked well!
    A.Like this
    16F887 (TX)----> (RX)18F4520(TX)------->MAX232--->PC COM PORT

    B.When I changed things to this
    18F4520 (TX)----> (RX)16F887(TX)------->MAX232--->PC COM PORT
    the problem occurs.
    Weird values at PC using MCS serial tool
    Please also note this is if PIC's are WIRED together (not wireless)
    In scenario B I check what the TX string is and it is what it's supposed to be in the serial tool window.
    If I check at the 16F887 side in serial tool window I get incorrect values for the data received :-(

    And that's what leads me to belive the problem lies at the 16F887 side .. but you may be right about the 18F4520 :-)
    At this stage I would try almost anything to solve the problem

    Kind regards
    Dennis

    PS.. Two fingers hey ? You're one up one me then :-) I'm like lightening on the keyboard ...never strike the same place twice :-)
    **************UPDATE***************
    On the transmitter PIC (18F4520) I am using this line
    Code:
    hserout [TRAIN,SYNK,XNUM,YNUM,ZNUM,$d,$a]
    On the receiver PIC (16f887)
    I use these two lines
    Code:
    hserin [WAIT(SYNK),XNUM,YNUM,ZNUM] ' (wait for synk byte)
    hserout["X-",DEC XNUM," Y-",DEC YNUM," Z-",DEC ZNUM,$d,$a] 'to PC com port
    If I remove this line
    Code:
    hserin [WAIT(SYNK),XNUM,YNUM,ZNUM] ' (wait for synk byte)
    The I see data appearing in the serial tool window, obviously without the data I am sending.
    So there seems to be a problem with HSERIN on the receiver PIC or what is being sent by the Transmitter PIC.
    Last edited by Dennis; - 18th December 2009 at 02:17. Reason: UPDATE!!!!!

  6. #6


    Did you find this post helpful? Yes | No

    Default Rcsta

    Hello again

    Try RCSTA = %10010000
    Tried that ..still no luck.

    By the way this is the 16f887 on the Pickit 2 44-pin demo board.

    Regards
    Dennis

Similar Threads

  1. HSERIN/OUT Wrong
    By Kaldurenik in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th October 2007, 10:40
  2. HSERIN/OUT or Serin/Out for AIR Link
    By mankan in forum General
    Replies: 4
    Last Post: - 25th May 2006, 15:19
  3. Hserin
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 20th March 2006, 23: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