16f887 and hserin/out


Closed Thread
Results 1 to 13 of 13

Hybrid View

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

  2. #2


    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!!!!!

  3. #3


    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

  4. #4


    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 !!

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

  6. #6


    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.

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

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