Hello
Using 18F66K22 (internal osc 16mhz)with FC5....need to use baud rate of 115200. In RS232 panel settings
i have set the "custom" baudrate to 115200. But, the baud rate is not correct. Checked
by sending string from Uart1/2 to Hyperterminal. Only get garbled chars.....
Tried same test with different compiler....works no problem.
Help?
Thanx
Mark
Baud Rate problem FC5 - 18F66K22
Moderator: Benj
- 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: Baud Rate problem FC5 - 18F66K22
Hi Mark,
Can you try again at a lower baud say 9600 and just check to see if this is working ok. Could be that Microchip have added a * 2 or / 2 into the setup of the baud on this device. If 9600 doesn't work and you still get garbled data then try setting the embedded device baud to 4800 and keep the PC baud at 9600. If this doesn't work then you can also try the embedded device at 19200 and keep the PC baud at 9600.
Let me know how you get on.
Can you try again at a lower baud say 9600 and just check to see if this is working ok. Could be that Microchip have added a * 2 or / 2 into the setup of the baud on this device. If 9600 doesn't work and you still get garbled data then try setting the embedded device baud to 4800 and keep the PC baud at 9600. If this doesn't work then you can also try the embedded device at 19200 and keep the PC baud at 9600.
Let me know how you get on.
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
-
- Flowcode v5 User
- Posts: 118
- Joined: Thu Sep 17, 2009 1:30 pm
- Has thanked: 3 times
- Been thanked: 11 times
- Contact:
Re: Baud Rate problem FC5 - 18F66K22
Hi Ben
Yup, tried 9600 / 19200 / 38400....all work.
Soon as you set 115200 on the "custom" baud rate setting, the data is garbled.
I know 115200 works, because i used it with a bootloader i used with another
compiler. That works flawlessly....
Something is not being calculated properly
Thanx
Mark
Yup, tried 9600 / 19200 / 38400....all work.
Soon as you set 115200 on the "custom" baud rate setting, the data is garbled.
I know 115200 works, because i used it with a bootloader i used with another
compiler. That works flawlessly....
Something is not being calculated properly
Thanx
Mark
- 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: Baud Rate problem FC5 - 18F66K22
Hi Mark,
Ok thanks for letting me know,
Does the 9600 work on the custom setting?
Also have you tried multiples of the baud on the PC e.g. set the baud to 115200 on the device but then use a baud of 57600 on the PC and see if that works. I know there is a divide by two flag on most devices so this could be being setup incorrectly. If this is the case then it helps me to track down where in the code the problem lies.
Hard to test here because that device is one of the newer families and requires a SMD circuit board to drive it.
If you can't get any further then let me know and I will have a dig in here to see if I can get anywhere.
Ok thanks for letting me know,
Does the 9600 work on the custom setting?
Also have you tried multiples of the baud on the PC e.g. set the baud to 115200 on the device but then use a baud of 57600 on the PC and see if that works. I know there is a divide by two flag on most devices so this could be being setup incorrectly. If this is the case then it helps me to track down where in the code the problem lies.
Hard to test here because that device is one of the newer families and requires a SMD circuit board to drive it.
If you can't get any further then let me know and I will have a dig in here to see if I can get anywhere.
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
-
- Flowcode v5 User
- Posts: 118
- Joined: Thu Sep 17, 2009 1:30 pm
- Has thanked: 3 times
- Been thanked: 11 times
- Contact:
Re: Baud Rate problem FC5 - 18F66K22
Hi Ben
I set the custom baud again 115200 (its the only way to select 115200)....and tried all different
baud rates on the PC side....not working, garbled data.
Tried setting 9600 on the "custom" method....works OK.
This might give you some clue? I have an idea that when you enter "115200" on the custom baud
setting, because it is 6 digits, that might be a problem for the holding variable for the custom
number?
I gotta fix this, as i need to have this program done in FC5. I am doing it for somebody
that has requested it from me.
cheers
Mark
I set the custom baud again 115200 (its the only way to select 115200)....and tried all different
baud rates on the PC side....not working, garbled data.
Tried setting 9600 on the "custom" method....works OK.
This might give you some clue? I have an idea that when you enter "115200" on the custom baud
setting, because it is 6 digits, that might be a problem for the holding variable for the custom
number?
I gotta fix this, as i need to have this program done in FC5. I am doing it for somebody
that has requested it from me.
cheers
Mark
- 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: Baud Rate problem FC5 - 18F66K22
Hi Mark,
Right looking at the calculation for the baud rate.
At 16MHz you end up with 7.68 which due to integer maths rounds to 7 which is probably just outside of the tolerance which means you get garbage instead of the correct data.
Is there any chance you can change the oscillator speed to give you more overhead to hit the baud rate on the nose, 19.6608MHz is a nice crystal for generating bauds.
If not then it should be possible to overwrite the baud calculation and plug in your own baud value. I'm guessing 8 would be better then 7 and hopefully will be in tolerance.
To do this open the CAL file C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_UART.c in a text editor.
On line 119 change this code
To this
Let me know how you get on.
Right looking at the calculation for the baud rate.
Code: Select all
#define MX_HARD_BAUD_1 (((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16)
Is there any chance you can change the oscillator speed to give you more overhead to hit the baud rate on the nose, 19.6608MHz is a nice crystal for generating bauds.
If not then it should be possible to overwrite the baud calculation and plug in your own baud value. I'm guessing 8 would be better then 7 and hopefully will be in tolerance.
To do this open the CAL file C:\Program Files (x86)\Flowcode\v5\CAL\PIC\PIC_CAL_UART.c in a text editor.
On line 119 change this code
Code: Select all
#define MX_HARD_BAUD_1 (((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16)
Code: Select all
#define MX_HARD_BAUD_1 8 //(((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16)
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
-
- Flowcode v5 User
- Posts: 118
- Joined: Thu Sep 17, 2009 1:30 pm
- Has thanked: 3 times
- Been thanked: 11 times
- Contact:
Re: Baud Rate problem FC5 - 18F66K22
Hi Ben
Will try that.....but will that not fix the baudrate at that speed? Since you are commenting out the calculation?
Just remember this...my other compiler works 100% at 115200 baud with my 16mhz clock speed (internal).
So, they are getting it right somehow....but FC5 is not calculating correctly.
Will give it a shot, but if the fix means that the baud remains fixed then that could also be a problem, but will see as the program
progresses.
Thanx!
Will try that.....but will that not fix the baudrate at that speed? Since you are commenting out the calculation?
Just remember this...my other compiler works 100% at 115200 baud with my 16mhz clock speed (internal).
So, they are getting it right somehow....but FC5 is not calculating correctly.
Will give it a shot, but if the fix means that the baud remains fixed then that could also be a problem, but will see as the program
progresses.
Thanx!
- 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: Baud Rate problem FC5 - 18F66K22
Hello,
If you don't want to hard code the calculation then you could try this instead.
The other compiler might be doing something fancy to do the calculation but i'm pretty sure it would also have to use 7 or 8 as the baud parameter and 7 isn't working. I might be able to get the pre-processor to round to the nearest value rather then always rounding down so I will have a look into this.
Out of interest what is your other compiler and can you find the value inside the SPBRG and TXSTA registers just to sanity check I'm not getting something wrong.
Yes we are hard coding but more for a quick sanity check to see if this starts the UART working at the correct baud rather then a long term fix.Will try that.....but will that not fix the baudrate at that speed? Since you are commenting out the calculation?
If you don't want to hard code the calculation then you could try this instead.
Code: Select all
#define MX_HARD_BAUD_1 ((((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16) + 1)
Out of interest what is your other compiler and can you find the value inside the SPBRG and TXSTA registers just to sanity check I'm not getting something wrong.
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
-
- Flowcode v5 User
- Posts: 118
- Joined: Thu Sep 17, 2009 1:30 pm
- Has thanked: 3 times
- Been thanked: 11 times
- Contact:
Re: Baud Rate problem FC5 - 18F66K22
Tried the +1 in the calculation....still not working.
I also tried hard coding the figures from 7 - 9. No luck.
Other compiler is the MikroBasic compiler for 12/16/18F devices.
I used this for the bootloader as they have nice library functions
for read/write to flash memory(cuz i am a lazy sod )
I will see if i can read out the registers and send out the serial port
in the morning and let you know whatsup.
Sorry to hassle you on this one Ben, it looks a bit nasty
I also tried hard coding the figures from 7 - 9. No luck.
Other compiler is the MikroBasic compiler for 12/16/18F devices.
I used this for the bootloader as they have nice library functions
for read/write to flash memory(cuz i am a lazy sod )
I will see if i can read out the registers and send out the serial port
in the morning and let you know whatsup.
Sorry to hassle you on this one Ben, it looks a bit nasty