UART with two differnt baudrates

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Contact:

UART with two differnt baudrates

Post by Dirk Bubley »

Hello FC community,

I try to find a way to in order to reconfigure the Hardware UART baud rate with in the running Programm.
Device is a PIC 18F series microcontroller.

Normally I setup/define in FC the baudrate i the UART properties. Of course this works fine.

In my new a design I want to start with 9600Baud and at a later stage in the Programm I want to Change to finally 115000Baud.

Has anyboda a idea how to achieve this.

BR
Dirk

User avatar
Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: UART with two differnt baudrates

Post by Benj »

Hi Dirk,

Is there a ChangeHWBaud macro available for the RS232 component? This should allow you to change the baud rate on the fly.

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Contact:

Re: UART with two differnt baudrates

Post by Dirk Bubley »

Hi Ben,

your are so right!! Great help!! Sometimes it is hard to see things that are in front of you/me.

ChangeHWBaud
Changes the hardware UART baud rate allowing for dynamic speed changes.
Parameters
BYTE NewBaud
0=1200, 1=2400, 2=4800, 3=9600, 4=19200, 5=38400, 6=57600, 7=115200



Is there a way to define acustomize baud rate too. Like for example 50000.

THX
Dirk

User avatar
Benj
Matrix Staff
Posts: 14929
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: UART with two differnt baudrates

Post by Benj »

Hello Dirk,

Currently custom baud rates are not supported but you can add support for them by editing the CAL file.

First copy the file "Flowcode 6\CAL\PIC\PIC_CAL_UART.c" to your desktop or another place where you can edit the file.

Open the file using a text editor such as notepad.

Near the top of the file you will find this section of code.

Code: Select all

	#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 1200) - 8) / 16)		//Was - 16 but had issues with rounding down
	#if (MX_HARD_BAUD_1200 > 255)
		#undef MX_HARD_BAUD_1200
		#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 1200) - 8) / 64)		//Was - 16 but had issues with rounding down
		#define MX_HARD_SLOW_1200	1
	#else
		#define MX_HARD_SLOW_1200	0
	#endif
Change to add your new baud rate in the calculation.

Code: Select all

	#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 50000) - 8) / 16)		//Was - 16 but had issues with rounding down
	#if (MX_HARD_BAUD_1200 > 255)
		#undef MX_HARD_BAUD_1200
		#define MX_HARD_BAUD_1200	(((MX_CLK_SPEED / 50000) - 8) / 64)		//Was - 16 but had issues with rounding down
		#define MX_HARD_SLOW_1200	1
	#else
		#define MX_HARD_SLOW_1200	0
	#endif
Save and copy the file back to the "Flowcode 6\CAL\PIC\" directory, you might want to make a backup of the file first so you can go back.

Then when calling the ChangeHWBaud pass the parameter as 0 to invoke the new overridden 1200 speed setting.

Hope this helps.

Dirk Bubley
Posts: 99
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Contact:

Re: UART with two differnt baudrates

Post by Dirk Bubley »

Hi Ben,

very good. Many thanks this is the Point I was looking for. :D

BR

Dirk

Post Reply