HSERIN / SERIN Problem with 16f690


Closed Thread
Results 1 to 25 of 25
  1. #1
    Join Date
    Oct 2008
    Posts
    10

    Default HSERIN / SERIN Problem with 16f690

    I've crawled the forum and have read several post about the 16f690 and serial in, I was wondering if someone could shed a little light on this topic for me. I have a simple setup with a 16f690 and a Max 232. I have tried both the internal oscillator and have just switched to a 3.579 MHZ crystal and still have not had success using HSERIN or SERIN to recieve in a character from Hyperterminal (2400 - 8N1). I can successfully send out characters using both HSEROUT and SEROUT. Below is my code, can someone tell me if I'm missing something? The code will output a character and then stop.
    Thank you for any insight.

    Rob


    Include "modedefs.bas"

    DEFINE OSC 3

    define HSER_RCSTA 90h
    define HSER_TXSTA 20h
    DEFINE HSER_BAUD 2400
    DEFINE HSER_ODD 1

    'DEFINE HSER_SPBRG 25

    'define CHAR_PACING 1000

    OSCCON= $08


    'this is the layout for portb.5 - RB5/AN11/RX/DT

    'turn off analog input for port b.5
    ANSELH=0
    'and any other analog stuff
    ANSEL=0

    'there's several analog comparators - lets shut them off
    'I dont know which one - shut them all off

    CM1CON0 =0
    CM2CON0 =0
    CM2CON1 =0

    adcon1=0
    'now set it for input
    trisb.5 = 1
    trisc.0 =1


    rxPin VAR portB.5
    txPin VAR portB.7
    rxVal Var Byte
    txVal Var Byte


    loop:
    pause 1000
    'serout txPin,T2400,["A"]
    hserout ["A"]
    Pause 1000
    'High Portb.6
    'Pause 1000
    'Low portb.6
    hserin [rxVal]
    'serin rxPin,T2400,rxVal
    'pause 500
    'serout txPin,T2400,[rxVal]
    hserout [rxVal]
    'High Portb.6
    'Pause 1000
    'Low portb.6
    pause 1000
    goto loop
    end

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    The code will output a character and then stop.
    Where is the serial input coming from and what is is sending?
    Dave
    Always wear safety glasses while programming.

  3. #3
    skimask's Avatar
    skimask Guest

    Default

    DEFINE HSER_ODD 1
    How is it working at all?
    Get rid of that line...

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

    Default

    From mr_e's PIC MULTICALC . . .
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 92  ' 2400 Baud @ 3.579MHz, 0.21%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    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
    Join Date
    Oct 2008
    Posts
    10

    Default

    Quote Originally Posted by mackrackit View Post
    Where is the serial input coming from and what is is sending?
    Input is coming from me typing characters in Hyperterminal.

  6. #6
    Join Date
    Oct 2008
    Posts
    10

    Default

    Quote Originally Posted by skimask View Post
    How is it working at all?
    Get rid of that line...
    Okay done. I was trying all kinds of things and forgot to remove that line. Please see my new post below.

    Rob

  7. #7
    Join Date
    Oct 2008
    Posts
    10

    Default

    Quote Originally Posted by Joe S. View Post
    From mr_e's PIC MULTICALC . . .
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 92  ' 2400 Baud @ 3.579MHz, 0.21%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Okay. Below is my new code (I've added an LED to port b.6). Here's what happens. A capital 'A' shows on the terminal window, the LED goes on, the LED then goes out, another 'A' shows on the terminal, the LED goes on and there is where it stays. I never touched the keyboard during this time. After this process, it doesn't matter what I type in the terminal window, the light stays on and nothing else happens. Any thoughts?


    Include "modedefs.bas"

    DEFINE OSC 3

    define HSER_RCSTA 90h
    define HSER_TXSTA 24h

    DEFINE HSER_SPBRG 92
    DEFINE HSER_CLROERR 1


    OSCCON= $08


    'this is the layout for portb.5 - RB5/AN11/RX/DT

    'turn off analog input for port b.5
    ANSELH=0
    'and any other analog stuff
    ANSEL=0

    'there's several analog comparators - lets shut them off
    'I dont know which one - shut them all off

    CM1CON0 =0
    CM2CON0 =0
    CM2CON1 =0

    adcon1=0
    'now set it for input
    trisb.5 = 1
    trisc.0 =1


    rxPin VAR portB.5
    txPin VAR portB.7
    rxVal Var Byte
    txVal Var Byte


    loop:
    pause 1000
    'serout txPin,T2400,["A"]
    hserout ["A"]
    Pause 1000
    High Portb.6
    Pause 1000
    'Low portb.6
    hserin [rxVal]
    'serin rxPin,T2400,rxVal
    'pause 500
    'serout txPin,T2400,[rxVal]
    hserout [rxVal]
    Low portb.6
    pause 1000
    goto loop
    end

  8. #8
    skimask's Avatar
    skimask Guest

    Default

    How about just a simple 'echo-ing' program to make sure everything is working first

    Code:
    Include "modedefs.bas"
    DEFINE OSC 3
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG  92
    DEFINE HSER_CLROERR 1
    Char VAR BYTE : led var portb.6 : output led : input portb.5 : output portb.7
    Main: HSERIN [Char] : led = 1 : HSEROUT [Char] : pause 10 : led = 0 : GOTO Main
    END
    Type on the PC, characters should show up on the PC. Led should blink once for each character received/sent-back. Don't type any faster than 54 characters per second.

  9. #9
    Join Date
    Oct 2008
    Posts
    10

    Default

    Skimask,
    Okay, I put in your program. The light blinks once (when I release from reset - I don't touch anything), no character is displayed and that's it. I tried putting a HSEROUT before your main loop and it does send out a character. Any thoughts about turning off the built in analog stuff?


    Rob

  10. #10
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by rborsuk View Post
    Skimask,
    Okay, I put in your program. The light blinks once (when I release from reset - I don't touch anything), no character is displayed and that's it. I tried putting a HSEROUT before your main loop and it does send out a character. Any thoughts about turning off the built in analog stuff?
    My bad...yes, turn off all of the analog ports...everything over to digital.
    Code:
    Include "modedefs.bas"
    DEFINE OSC 3
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_SPBRG  92
    DEFINE HSER_CLROERR 1
    cm1con0 = 0 : cm2con0 = 0 : ansel = 0 : anselh = 0
    Char VAR BYTE : led var portb.6 : output led : input portb.5 : output portb.7
    led=1 : pause 500 : led=0 : pause 500 : led=1 : pause 500 : led=0 : pause 500
    Main: HSERIN [Char] : led = 1 : HSEROUT [Char] : pause 10 : led = 0 : GOTO Main
    END
    Last edited by skimask; - 28th October 2008 at 16:11.

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Are you sure the PIC is running? Try a quick "blinky" without any serial stuff.
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Oct 2008
    Posts
    10

    Default

    Mackrackit,
    Yep, it's running. Follow the rest of my reply.
    Skimask,
    Sorry for the delay. I wanted to try some additional things. I'll explain in a bit. I tried the new code. It produces two long flashes on the LED and one very quick one. It then does nothing. No characters are displayed on the terminal and I can't enter anything. Thinking that it might be something else, I traded out the Max232 with a Max233 (eliminated the caps and such). Same results. I then tried a new 16F690 (thinking that the other one might have been damaged), same results. Anything we're missing here?

    Rob

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Floating MCLR?
    LVP is OFF?
    Noisy PSU?
    Poor contact, low battery, are some other great tests..

    You could also begin your program with something like...
    Code:
    START:
            HSEROUT ["1,2,1,2 TESTING....",13,10]
            FOR MyVAR=0 TO 250
                    HSEROUT ["MyVAR=",#MyVAR,13,10]
                    NEXT
            GOTO START
    Last edited by mister_e; - 30th October 2008 at 02:06.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    skimask's Avatar
    skimask Guest

    Default

    Does the F690 run from the external crystal by default?
    Try removing DEFINE OSC 3 and see what happens.

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    default config line is...
    Code:
     device  pic16F690, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
    We don't see any config fuse setting here, so this would make some sense...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    Join Date
    Oct 2008
    Posts
    10

    Default

    This is my config line

    Code:
     __config _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF

    Rob

  17. #17
    Join Date
    Oct 2008
    Posts
    10

    Default

    Success!!
    Okay, same setup. Same code. This time compiling was done with the melabs compiler (instead of mpasm) and downloaded with a pickit2 (instead of an ICD2). I'm going to investigate this more and post my findings.

    Rob

  18. #18
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Quote Originally Posted by rborsuk View Post
    Success!!
    Okay, same setup. Same code. This time compiling was done with the melabs compiler (instead of mpasm) and downloaded with a pickit2 (instead of an ICD2). I'm going to investigate this more and post my findings.

    Rob
    Great!!

    Are you setting the configs in you code or the inc file?
    Dave
    Always wear safety glasses while programming.

  19. #19
    Join Date
    Oct 2008
    Posts
    10

    Default

    I was setting them in the 16F690.INC file in the PicBasic Pro (PBP) folder. That's the right spot, correct?

    Rob

  20. #20
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Quote Originally Posted by rborsuk View Post
    I was setting them in the 16F690.INC file in the PicBasic Pro (PBP) folder. That's the right spot, correct?

    Rob
    That is the spot.
    The are two sections in that file. One for MELABS and one for MPASAM.

    Just wondering if you are modifying the settings for MELAB and not MPASAM?
    Dave
    Always wear safety glasses while programming.

  21. #21
    Join Date
    Oct 2008
    Posts
    10

    Default

    Here's the exact include I was using with mplabs

    Code:
            NOLIST
        ifdef PM_USED
            LIST
            include 'M16F6xx.INC'	; PM header
            device  pic16F690, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
            XALL
            NOLIST
        else
            LIST
            LIST p = 16F690, r = dec, w = -302
            INCLUDE "P16F690.INC"	; MPASM  Header
            ;* __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
    		__config _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
            NOLIST
        endif
            LIST
    When I switched to melabs, I modified the top one. I'm guessing that the pickit / icd2 wasn't the problem but maybe a difference in the compiler. What do you think?
    Rob

  22. #22
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    I think you always should comment all default config line (both for MPASM and PM, DEVICE and CONFIG lines) and then set your config fuses in your code.

    Way more handy, because you don't need to remember each time which fuses you have hidden for a XYZ project using the same PIC.

    Have a look at the following, post #1 and #5 are all you need for now.
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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

    Default

    Easier, I think to just comment them out and set them in your code every time. If you do not want to type, then make a file with all the setup code you use most often and open it everytime you start a new project, and save as, before your first compile.
    EDIT: Mister_e, fast on the draw!
    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.

  24. #24
    Join Date
    Jan 2010
    Location
    Detroit, Michigan, USA
    Posts
    2

    Default 16f690 Hserin problem

    Hello:

    I am having this same issue; what was the solution?

    Thanks,
    TomC

  25. #25
    Join Date
    Jan 2010
    Location
    Detroit, Michigan, USA
    Posts
    2

    Default 16f690 HSERIN Problem

    I neglected to set the ANSEL and ANSELH to 0!!!

    TomC

Similar Threads

  1. HSERIN problem
    By eggman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th October 2007, 21:31
  2. Serin Problem 16f819
    By jjohannson in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd March 2007, 22:50
  3. SERIN AND SEROUT PROBELM USING 16f690 PIC
    By Charles in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 18th January 2007, 03:59
  4. Problem with PBP interrupt and Serin, please help
    By rgregor in forum mel PIC BASIC
    Replies: 0
    Last Post: - 22nd August 2006, 19:02
  5. HSERIN problem
    By s_syafiq81 in forum Serial
    Replies: 2
    Last Post: - 1st January 2006, 11:05

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