HSER baudrate


Closed Thread
Results 1 to 15 of 15

Thread: HSER baudrate

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755

    Default HSER baudrate

    Hello,
    I'm not very familiar with the hardware serial port. So far I have used define.
    But when I tried this:
    Code:
    HSerBaud var byte
    IF HSerBaud=0 THEN
     DEFINE HSER_BAUD 300
    ENDIF
    IF HSerBaud=1 THEN
       DEFINE HSER_BAUD 2400
    ENDIF
    IF HSerBaud=$BD THEN
       DEFINE HSER_BAUD 9600
    ENDIF
    I got an error, Redefininig symbor that can not be redefined...
    I do not know what registers should be set to change the baud rate.
    If you can help, so I would not read the whole datasheet. I'm using PIC18LF14K50.
    Thanks

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

    Default Re: HSER baudrate

    That's is correct as far as I know, you cannot redefine it in running code, you can however select it in the beginning as your PIC starts. Look at the code example in the lower 1/2 of this article. I show you how to do it there.

    http://www.picbasic.co.uk/forum/content.php?r=171-LCD-serial-backpacks

    Last edited by Archangel; - 12th June 2011 at 00:46.
    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
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: HSER baudrate

    If you need to change the baud rate during run time do not use defines. Deal with the registers directly.
    Code:
    X VAR WORD
        START:
         RCSTA.4 = 0 : RCSTA.4 = 1
         RCSTA=$90:TXSTA=$24:SPBRG=129
         HSERIN [dec X]
         HSEROUT [DEC X.7,13]
    blah
    blah
    Dave
    Always wear safety glasses while programming.

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

    Default Re: HSER baudrate

    or there's Dave's way . . .
    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
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default Re: HSER baudrate

    When changing baudrate on the fly, you want to turn off the USART before though.

    RCSTA=0
    SPBRG=xyz
    TXSTA = whatever, assuming it's value change from baudrate to baudrate
    RCSTA=$90
    Steve

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

  6. #6
    Join Date
    Sep 2009
    Posts
    755

    Default Re: HSER baudrate

    Thanks, guys.
    Both examples helped me. Just to see which registers should be set. Today I'll try ..

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