Announcement

Collapse
No announcement yet.

Changing Baud Rates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Changing Baud Rates

    I'm working with an ELM327 OBD II to USART Interpreter (communicates with 1996+ automotive ECUs). It initializes at 38400 Baud. It has faster options, which I'd like to capitalize on. Once a faster option is programmed, it will always communicate at that faster Baud rate from that point onward. I tried DEFINE-ing HSER_BAUD at 115200 in the upper portion of my code, then reDEFINE-ing it at the 38400 rate in the subroutine that initializes the ELM327. The compiler gave me an error for DEFINE-ing the same thing more than once.

    I see only one option; use SPRG1H/SPRG1/Sync/BRGH/BRH to define baud rate in both instances. I worked out the math, but I haven't breadboarded it yet. Will the HSERIN/OUT Commands work without the appropriate HSER1_BAUD DEFINE since I can't declare it twice? Ideally I'd like to structure the Header DEFINE for the 115200 (default) and change it in the "used only once" subroutine to 38400. Experienced thoughts appreciated.
    Last edited by mpgmike; 10-04-2017, 06:27 PM.
    We can crack this cotton PIC'n thang!

  • #2
    mpgmike, I have never used the HSEROUT or HSERIN commands but, I have always used the serial programmable baud rate generator registers directly in any of my code. One program in particular I use it to switch between 10.24k, 19.2k and 38.4k for one of the 2 UART channels.
    Dave Purola,
    N8NTA
    EN82fn

    Comment


    • #3
      OK...................
      ..........................
      You got me thinking.......
      We can crack this cotton PIC'n thang!

      Comment


      • #4
        DEFINE is a compiler/assembler directive - not a runtime command.
        It's a one shot kind of deal, telling the compiler/assembler "how"to generate code for a specific thing, it can't be used to CHANGE things at runtime.

        You can change the baudrate as much and as many times as you want by setting the USART configuration registers to whatever is needed and HSEROUT will work with that but then don't include any DEFINES related to the USART.

        /Henrik.

        Comment


        • #5
          Thanks all.
          We can crack this cotton PIC'n thang!

          Comment

          Working...
          X