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
UART with two differnt baudrates
Moderator: Benj
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: UART with two differnt baudrates
Hi Dirk,
Is there a ChangeHWBaud macro available for the RS232 component? This should allow you to change the baud rate on the fly.
Is there a ChangeHWBaud macro available for the RS232 component? This should allow you to change the baud rate on the fly.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
Re: UART with two differnt baudrates
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
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
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: UART with two differnt baudrates
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.
Change to add your new baud rate in the calculation.
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.
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
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
Then when calling the ChangeHWBaud pass the parameter as 0 to invoke the new overridden 1200 speed setting.
Hope this helps.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 99
- Joined: Fri Feb 02, 2007 3:54 pm
- Location: Germany
- Has thanked: 14 times
- Been thanked: 12 times
- Contact:
Re: UART with two differnt baudrates
Hi Ben,
very good. Many thanks this is the Point I was looking for.
BR
Dirk
very good. Many thanks this is the Point I was looking for.
BR
Dirk
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: UART with two differnt baudrates
Hello All!
I am trying to use 4Mhz crystal on a 18F4523 and 1200 baud rate on UART and the code is not working correctly.
I have successfully use custom baudrate of 1200 on the same device but the crystal frequency was 19.660800 Mhz and the C code at the beginning of the program was as below:
TXSTAbits.BRGH=0;
BAUDCONbits.BRG16=0;
SPBRGH=0;
SPBRG=255; //this value is for 1200baud rate
What is the settings for 4Mhz crystal on a 18F4523 and 1200 baud rate on UART?
I tried to use the table bellow but the program is not working correctly.
Thanks in advance
George
I am trying to use 4Mhz crystal on a 18F4523 and 1200 baud rate on UART and the code is not working correctly.
I have successfully use custom baudrate of 1200 on the same device but the crystal frequency was 19.660800 Mhz and the C code at the beginning of the program was as below:
TXSTAbits.BRGH=0;
BAUDCONbits.BRG16=0;
SPBRGH=0;
SPBRG=255; //this value is for 1200baud rate
What is the settings for 4Mhz crystal on a 18F4523 and 1200 baud rate on UART?
I tried to use the table bellow but the program is not working correctly.
Thanks in advance
George
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: UART with two differnt baudrates
You don't need code for 1200 as that is not a custom rate, you just choose 1200 within UART properties.
Just make sure the timings are correct with a one-sec flasher test first.
Just make sure the timings are correct with a one-sec flasher test first.
Martin
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: UART with two differnt baudrates
thank you for your reply.medelec35 wrote: ↑Sat Jan 08, 2022 6:44 pmYou don't need code for 1200 as that is not a custom rate, you just choose 1200 within UART properties.
Just make sure the timings are correct with a one-sec flasher test first.
I tried to set the baudrate at 1200 in UART properties but it is not working. Note that i want to use software defined pins and not the default hardware pins. Does this make the difference and the program is not working at 1200?
Regards
George
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: UART with two differnt baudrates
Yes, on V8 it does.
Getting the baud to work at the correct rate for software on all targets is very time-consuming.
For example, my target device is 16F1937.
I have set the software baud to 1200. The measure baud is 917 = 23.6% error.
New to V9, there is a UART software (timer) component that uses a timer interrupt to generate a baud which is bang on the money.
With V9 even though 1200 is a standard baud rate, you will need to use custom to get it working.
A tip I always used to determine the UART baud rate.
Send a string with U it must be in upper case.
measure any single pulse width.
Baud = 1/singe pulse duration.
I did that for 4MHz and with a custom baud set at 1719, the baud is 1251 on hardware.
You will be best having a slightly faster baud as if you have any interrupts, the baud will be slowed down.
Martin