PDA

View Full Version : Changing Baud Rates



mpgmike
- 5th October 2017, 03:16
I’m working with an ELM327 OBD to USART Interpreter (communicates with 1996+ automotive ECUs). It initializes at 38400 Baud. It has faster options, which I want to capitalize upon. Once a faster option is programmed, it will always communicate at that faster Baud rate from that point onward. I tried DEFINE-ing HSER1_BAUD at 115200 in the upper portion of my code, and 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/BRG 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 and change it in the “used only once” subroutine to the 38400. Experienced thoughts appreciated.

MichelJasmin
- 5th October 2017, 04:01
I’m working with an ELM327 OBD to USART Interpreter (communicates with 1996+ automotive ECUs). It initializes at 38400 Baud. It has faster options, which I want to capitalize upon. Once a faster option is programmed, it will always communicate at that faster Baud rate from that point onward. I tried DEFINE-ing HSER1_BAUD at 115200 in the upper portion of my code, and 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/BRG 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 and change it in the “used only once” subroutine to the 38400. Experienced thoughts appreciated.

Go with SPRG1H/SPRG1/Sync/BRGH/BRG, works fine for changing baudrate anytime in your code.

Also, get Mr E's Multicalc: http://www.picbasic.co.uk/forum/showthread.php?t=19638&p=130286#post130286 it's a real helper!

mpgmike
- 5th October 2017, 09:53
Many thanks. Clicking on that link was like going to the store for just a loaf of bread...while you're hungry. You come back with a cart full of stuff you didn't know you needed.