UART with two differnt baudrates

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

Moderator: Benj

Dirk Bubley
Posts: 89
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 9 times
Been thanked: 8 times
Contact:

UART with two differnt baudrates

Postby Dirk Bubley » Fri Nov 17, 2017 7:20 pm

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: 14566
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4595 times
Been thanked: 4238 times
Contact:

Re: UART with two differnt baudrates

Postby Benj » Mon Nov 20, 2017 11:53 am

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: 89
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 9 times
Been thanked: 8 times
Contact:

Re: UART with two differnt baudrates

Postby Dirk Bubley » Mon Nov 20, 2017 8:51 pm

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: 14566
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4595 times
Been thanked: 4238 times
Contact:

Re: UART with two differnt baudrates

Postby Benj » Tue Nov 21, 2017 11:18 am

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.
These users thanked the author Benj for the post:
Dirk Bubley (Thu Nov 23, 2017 8:06 pm)
Rating: 5.26%
 

Dirk Bubley
Posts: 89
Joined: Fri Feb 02, 2007 3:54 pm
Location: Germany
Has thanked: 9 times
Been thanked: 8 times
Contact:

Re: UART with two differnt baudrates

Postby Dirk Bubley » Tue Nov 21, 2017 12:15 pm

Hi Ben,

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

BR

Dirk
These users thanked the author Dirk Bubley for the post:
Benj (Fri Nov 24, 2017 11:58 am)
Rating: 5.26%