Hserout questions
+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default Hserout questions

    Hi All

    Attempting to get some serial communication working with a 16f628 (4Meg Xtal) My defines are as below :-


    DEFINE OSC 4
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_SPBRG 25

    It works sometimes but not reliably ..... Any issues with above, ///maybe external xtal too slow ?

    Just looking for a little guidance.

    BR
    Andy

  2. #2

    Default Re: Hserout questions

    Try adding

    DEFINE HSER_CLROERR 1

  3. #3
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default Re: Hserout questions

    Quote Originally Posted by aerostar View Post
    Try adding

    DEFINE HSER_CLROERR 1
    I have ..... Still intermittent coms 🙄

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,193

    Default Re: Hserout questions

    Quote Originally Posted by andybarrett1 View Post
    Hi All

    Attempting to get some serial communication working with a 16f628 (4Meg Xtal) My defines are as below :-
    ...
    Andy
    By Xtal, do you mean that an external 4Mhz crystal with two caps like 22pf?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default Re: Hserout questions

    Yes 4Megs Crystal

  6. #6

    Default Re: Hserout questions

    Your serial circuit diagram/connection details would help - what is connected to the TX line ?

    Is it just TX that is the problem ? have you tried RXing ?

    Have you tried lower rates ?

    Do you have a good earth between your PIC and whatever is receiving. ?

    Is there a short on the TX pin to an adjacent pin ?

    What do you mean by unreliable ? wrong characters/no characters/locking up.

  7. #7
    Join Date
    Oct 2009
    Posts
    595

    Default Re: Hserout questions

    For a 4Mhz timing at 9600 baud

    Register settings

    Code:
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $20   ' Enable transmit, BRGH = 0
    SPBRG = 25    ' 9600 Baud @ 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    And the defines

    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 25  ' 9600 Baud @ SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    Details of the circuit and what you are sending / receiving, and what's at the other end of the serial cable would help

  8. #8

    Default Re: Hserout questions

    BAUDCON does not appear in 628 or 628a data sheet.

    MisterE Multicalc shows

    Registers

    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $24 ' Enable transmit, BRGH = 1
    SPBRG = 25 ' 9600 Baud @ 4MHz, 0.16%

    PBP DEFINES

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 25 ' 9600 Baud @ 4MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically

  9. #9
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237

    Default Re: Hserout questions

    Hi All

    Thanks for all your advice guys.... Turns out I was right with the defines except the 9600 should have been 9615

    The thing that fixed it all was putting a small delay (pause 100) between my serial instructions ?

    Anyway all good now !

    Thank you

    Andy

Similar Threads

  1. Replies: 1
    Last Post: - 31st October 2016, 09:40
  2. Questions about using the A to D
    By Ramius in forum FAQ - Frequently Asked Questions
    Replies: 18
    Last Post: - 1st September 2014, 17:22
  3. pic16f88 Serial questions (hserin/hserout, etc.)
    By harralk in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th October 2012, 00:29
  4. 2 questions
    By Archangel in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 1st December 2006, 03:47
  5. New with questions
    By Terke in forum General
    Replies: 5
    Last Post: - 6th December 2005, 07:35

Members who have read this thread : 16

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