Page 1 of 1

Custom Baud rate assistance

Posted: Tue May 15, 2018 3:26 pm
by Ondra
Good day all.
I am working with a esp8266 module. On start up is spits out data at a fixed baud rate of 74880. I want to be able to receive at the fixed rate than change over to 2400 bps. looking at the help file my options don't allow me to select outside of the options available. I thought to set the main speed to 74880 then change to 2400, question is how do I convert back to the custom speed of 74880 and or how do I add a custom speed to the ChangeHWBaud (Newbaud) function?

ChangeHWBaud (Newbaud)
Allows the baud rate for a hardware UART channel to be updated on the the fly.
The New baud parameter specifies the rate for the new baud.
0 = 1200 bps
1 = 2400 bps
2 = 4800 bps
3 = 9600 bps
4 = 19200 bps
5 = 38400 bps
6 = 57600 bps
7 = 115200 bps

Re: Custom Baud rate assistance

Posted: Tue May 15, 2018 5:36 pm
by Benj
Hello,

If you look in the PIC_CAL_UART file in the "Flowcode 5\PIC\CAL\PIC\" folder using a text editor.

Browse to line 317 and you should see this section of code.

Code: Select all

	#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 1200) - 16) / 16)
	#if (MX_HARD_BAUD_1200 > 255)
		#undef MX_HARD_BAUD_1200
		#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 1200) - 16) / 64)
		#define MX_HARD_SLOW_1200	1
	#else
		#define MX_HARD_SLOW_1200	0
	#endif
Change the 1200 for your new rate 74880 and you can then use the 1200 baud setting in the ChangeHWBaud function to switch to 74880.

Code: Select all

	#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 74880 ) - 16) / 16)
	#if (MX_HARD_BAUD_1200 > 255)
		#undef MX_HARD_BAUD_1200
		#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 74880 ) - 16) / 64)
		#define MX_HARD_SLOW_1200	1
	#else
		#define MX_HARD_SLOW_1200	0
	#endif
Of course you could override any of the other baud rates or even append your own rates to the end, I just chose 1200 because it's the first one.

Re: Custom Baud rate assistance

Posted: Wed May 16, 2018 4:06 pm
by Ondra
Hi Benj
Thanks for the quick response. I made the changes but I just get garbled characters.
I created an echo loop that takes/captures the received character and sends it back via second port.
I also did this with the native usart values and it worked fine. If it makes a difference and if it helps
I am using a Pic 18lf46k80 with a 19660800 external crystal .

Re: Custom Baud rate assistance

Posted: Thu May 17, 2018 4:24 pm
by Ondra
Good day all.
Hi Ben, any additional suggestions on this?
thanks in advance

Re: Custom Baud rate assistance

Posted: Wed May 23, 2018 11:39 am
by Benj
Hi Ondra,

I'm not sure I can suggest much more for you, maybe you could post your modified file and I'll have a quick look.

v5 and for that matter v6 is no longer under support so I can't do too much.

Are you sure of the baud rate of the initial data?