Custom Baud rate assistance

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Custom Baud rate assistance

Postby Ondra » Tue May 15, 2018 3:26 pm

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

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: Custom Baud rate assistance

Postby Benj » Tue May 15, 2018 5:36 pm

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.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Custom Baud rate assistance

Postby Ondra » Wed May 16, 2018 4:06 pm

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 .

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Custom Baud rate assistance

Postby Ondra » Thu May 17, 2018 4:24 pm

Good day all.
Hi Ben, any additional suggestions on this?
thanks in advance

User avatar
Benj
Matrix Staff
Posts: 14307
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4400 times
Been thanked: 4126 times
Contact:

Re: Custom Baud rate assistance

Postby Benj » Wed May 23, 2018 11:39 am

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?