Changing Baud Rate from within a Program


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Mar 2004
    Location
    UK-Midlands
    Posts
    84

    Default Changing Baud Rate from within a Program

    Hi,

    Have searched and re-read the PBP Manual but can't see the solution!

    Using the USART I can't seem to select a Baud rate from within a program.
    Am I missing something obvious!!! or can't it be done?
    I define the port at the start as shown:

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_SPBRG 32
    DEFINE HSER_CLROERR 1

    But any attempt to change these values brings a compiler error.

    I had no problems with the software commands SERIN2 or SEROUT2.

    Thanks,
    Bob

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobP View Post
    Hi,
    Have searched and re-read the PBP Manual but can't see the solution!
    Using the USART I can't seem to select a Baud rate from within a program.
    Am I missing something obvious!!! or can't it be done?
    I define the port at the start as shown:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_SPBRG 32
    DEFINE HSER_CLROERR 1
    But any attempt to change these values brings a compiler error.
    I had no problems with the software commands SERIN2 or SEROUT2.
    Thanks,
    Bob
    Change the baud rate generator registers for your particular serial port for your particular PIC directly from within the program...i.e. SPBRG = $90, or whatever...

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I do this all the time. Just write the appropriate value to the SPBRG register as Skimask suggests.
    Charles Linquist

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    I do this all the time. Just write the appropriate value to the SPBRG register as Skimask suggests.
    I was just guessing, but thanks for confirming what I was thinking...another tool to use in the future...

  5. #5
    Join Date
    Mar 2004
    Location
    UK-Midlands
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Thanks for the replies. I think my problem was to use the 'DEFINE' statment again.
    Will try to update register directly.

    Many thanks,
    Bob

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Bob,

    Here's a macro that might help make changing baud rates easier for you.

    http://www.picbasic.co.uk/forum/show...7&postcount=20

    HTH,

    Added:
    Oops, just realized that one was for 18F's only.
    Here's one that works on 16F's too...

    http://www.picbasic.co.uk/forum/showthread.php?p=17574
    <br>
    Last edited by Darrel Taylor; - 3rd May 2007 at 01:04. Reason: 16F version
    DT

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. PIC 18f1220 EUSART Baud Rate Cache Problem
    By wklose99 in forum Off Topic
    Replies: 3
    Last Post: - 15th April 2008, 00:39
  3. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 02:17
  4. PIC12F675, accuracy of baud rate with Internal Oscillator
    By Chris Mayhew in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 22:41
  5. Baud Rate and Timing Calculator
    By picnaut in forum General
    Replies: 3
    Last Post: - 23rd January 2004, 16:48

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