16f887 and hserin/out


Closed Thread
Results 1 to 13 of 13
  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

  7. #7


    Did you find this post helpful? Yes | No

    Default desperation

    Now I am trying the same thing using a 16f690 and having the same issue :-)
    HELP !!

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


    Did you find this post helpful? Yes | No

    Default

    From Mr_e's calculator using 8mhz and 2400 baud:
    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
    
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 51  ' 2400 Baud @ 8MHz, 0.17%
    for 16f690 :
    Code:
    
    DEFINE LCD_COMMANDUS 2000  ' Set command delay time in us
    
    DEFINE LCD_DATAUS 50      ' Set data delay time in us
    ' = = = = = Set analog functions to off condition = = = 
    ADCON0 = 0
    ADCON1=0
    ANSEL   = 0
    ANSELH  = 0
    CM1CON0 = 0
    CM2CON0 = 0
    
    OERR	    VAR	RCSTA.1	         ' Alias OERR (USART Overrun Error Flag)
    CREN	    VAR	RCSTA.4	         ' Alias CREN (USART Continuous Receive Enable)
    	
    	CREN = 0			' Disable continuous receive to clear overrun flag
    	CREN = 1			' Enable continuous receive
    Go Here and look at post 16"

    http://www.picbasic.co.uk/forum/show...light=backpack
    Post your non working code for the 690 so we can wrench on it a bit.
    Last edited by Archangel; - 19th December 2009 at 00:31.
    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.

  9. #9


    Did you find this post helpful? Yes | No

    Default code

    Hi Joe

    Been battling with this even more now... have read up on the registers
    Still, no go JOE :-)
    Here's the code
    receiver 16f690
    Code:
    '16F690 DEMO
        DEFINE OSC 8       'Comment the 4Mhz and uncomment these for 8Mhz
        OSCCON=%01110000
    
     '   DEFINE OSC 4           'This is the default setting
     '   OSCCON=%01100000
    
    ADCON0 = 0
    ADCON1=0
        
    
    ANSEL = 0
    ANSELH = 0
    CM1CON0 = 0
    CM2CON0 = 0
    'RCSTA = %10010000 
    'txsta=%10100000
    'rcsta=%10010000
    
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 25  ' 2400 Baud @ 4MHz, 0.17%
    
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 25  ' 2400 Baud @ 4MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    
        'The first line is if you are using PM, the second if you are using MPASAM
      '  @ device  pic16F690, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
      '  @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
            TRISA  = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, 
            TRISB = %00100000 'TX=PORTB.7 RX=PORTB.5
            TRISC = %00000000   '0 will make the pins an output, 1 will make them inputs
      
     
       'includes begin here
            INCLUDE "modedefs.bas"
            include "c:\pbp\samples\keypad.bas"
    'end of includes
    
        TRAIN   VAR BYTE
        train =  $B3
        SYNK    VAR BYTE
        SYNK = $7E
        
        XNUM    VAR BYTE
        YNUM    VAR BYTE
        ZNUM    VAR BYTE
        LED     var PORTC.0
        
      'Variables end here
    
      loopy:
       low LED '  LED on
       
        hserin [WAIT(SYNK),XNUM,YNUM,ZNUM]
        
    ' and now out to hyperterminal (or wherever!)
        hserout["X-",DEC XNUM," Y-",DEC YNUM," Z-",DEC ZNUM,$d,$a] 'to   hyperterminal
        toggle led
        Goto loopy  ' Go back to loop and blink LED forever
        End
    'End of all code
    Transmitter is 184520 (which receiver and sends perfectly well with hserin/out) working it as the transmitter is the problem I have :-( same as for a6F690

    Code:
    'USART defines and register settings begin here     - use for HSERIN/OUT
    'Ocsillator selections here
    'DEFINE OSC 8
    'OSCCON=%01110000
    'or
    'DEFINE OSC 4
    'OSCCON=%01100000
    'OSCTUNE.6 = 0 'PLL Multiplier disabled
    'OSCTUNE.6 = 1 'PLL 4x
    'Ocsillator selections here
            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
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 207 ' 2400 Baud @ 32MHz, 0.17%
    
    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
    
    TRISC = %10010000
    
    XNUM    VAR BYTE
            YNUM    VAR BYTE
            ZNUM    VAR BYTE
            TRAIN  VAR BYTE
            train =  $B3
            WNUM = 225
            XNUM = 31
            YNUM = 100
            ZNUM = 4
    hserin [WAIT(SYNK),XNUM,YNUM,ZNUM]
    Keep well Joe

    Kind regards
    Dennis
    Last edited by Dennis; - 19th December 2009 at 01:47.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Dennis,
    Ok so far here is what I see
    use this config: @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF & _PWRTE_OFF & _FCMEN_OFF

    use this
    OSCTUNE = 0 ' sets osc to calibrated value
    Mr._e's code ain't going to work on the 690 without changes because your USART is on portB
    so comment out the include keypad.bas
    throw this in before your tris statements
    PortA = 0
    PortB = 0
    PortC = 0
    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.

  11. #11


    Did you find this post helpful? Yes | No

    Default no go Joe !

    Hi Joe

    Thanks for the tips ...
    Have made the changes, set the fuses,cleared the VAR's checked the TRIS, removed the kepad include(accidently slipped in in somehow")....
    and still no luck :-(

    Any other ideas or tips ?



    Kind regards
    Dennis

  12. #12


    Did you find this post helpful? Yes | No

    Default Speed kills :-)

    YAY ...I'm now back at my original problem which prompted me to start this thread :-) or :-( ?

    In post #9 here I had used the wrong settings for the usart , if you look carefully you'll see that the values are set for 4 MHz and I had set to use the internal clock @ 8 MHz. I changed to use internal clock @ 4MHz and now at least I get values in hyperterminal....b ut they are WRONG !

    The HSEROUT line from the 18F4520 is as follows:
    [code]
    TRAIN VAR BYTE
    train = $B3
    SYNK VAR BYTE
    SYNK = $7E

    XNUM VAR BYTE
    YNUM VAR BYTE
    ZNUM VAR BYTE
    hserout [TRAIN,SYNK,XNUM,YNUM,ZNUM,$d,$a]
    [code]
    It works perfectly ... I can see the values in hyperterminal/MCS serial tool window as they are sent!
    So I see this
    ³~dE
    That's the numbers $B3,$7E,31,100,69

    Now when I'm at the receiver side the numbers I receiver PIC side are way different ...
    Here's the receiver code
    Code:
    hserin [WAIT(SYNK),XNUM,YNUM,ZNUM]
        
    ' and now out to hyperterminal (or wherever!)
        hserout["X-",DEC XNUM," Y-",DEC YNUM," Z-",DEC ZNUM,$d,$a] 'to hyperterminal
    Here's what I get in MCS serial tool window /hyperterminal

    X-71 Y-84 Z-53
    X-71 Y-84 Z-53
    X-71 Y-80 Z-53
    X-71 Y-80 Z-53
    X-71 Y-80 Z-53
    This should be X- 31,Y-100,Z-69
    These are completely di8fferent to what I am sending !

    This is really confuising ... can anyone see what I am doing wrong ?

    Kind regards
    Dennis

  13. #13


    Did you find this post helpful? Yes | No

    Default un-resolved!

    I have replaced the 16F690 with a 16f887 .... and now it's all working like a charm ... either it's me who has missed something or has overlooked something crucial or I have a dodgy 16f690.

    If anyone has suggestions please feel free to leave a message here.

    Kind 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 : 1

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