|
|
View previous topic :: View next topic |
Author |
Message |
fabien.casas
Joined: 28 Nov 2006 Posts: 6
|
advice needed for rs232 baudrate with #use rs232 |
Posted: Wed Nov 29, 2006 7:51 am |
|
|
Hi all,
I'm working on a 18F4550-based custom board, using CCS C Compiler v3.249, and I wanted to have some explanations on the #use rs232 directive, concerning the baudrate.
My "problem" is that, to achieve a 19200 bps baudrate, I have to set the rs232 directive like this :
Code: |
#use delay(clock=24000000)
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use rs232(baud=8100,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=pc)
|
Please notice that "baud" is set to 8100. This works fine, the final baudrate is about 19200 bps (I could check with an oscilloscope then with a serial terminal).
If I set "baud=19200", the final baudrate is about 45500 bps.
The "delay" setting is right (external osc. at 24MHz), but I'm not sure of my #fuses.
My sw is also using I2C, can there be conflicts with the BRG ?
I could try my sw with a CCS demo board: same PIC but with a 20MHz oscillator. I set the "delay" to 20M and the "baud" to 19200, and the final baudrate was 19200bps, as expected.
Finally, what I wanted to know is where does this "baudrate-setting inconsistency" comes from.
So, if someone has a clue...
Thanks!
fabien |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Wed Nov 29, 2006 8:23 am |
|
|
I'm not positive of all the possible options on the 18F4550, but this will most likely fix your problem until you can learn more about what you're doing:
Change XTAL to a 20MHZ.
Change #use delay to 20000000 (should match the value of your xtal, unless using PLL)
Change HSPLL fuse to HS
Change baud=8100 to baud=19200 (or whatever the precise baud rate is, that you desire)
Look at some of the other options for the #use rs232 statement, you may want to include them... ERRORS, BITS, etc.
The pros will give more details....
John |
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 29, 2006 8:48 am |
|
|
The 'clock' value, needs to be the frequency the CPU is running at, not the external oscillator. On the 4550, the external [spam] is divided, to generate 4MHz (PLLDIV5), and then multiplied by the internal USB PLL, to generate the 96MHz used by the USB circuitry. This is then fed to the CPU divider, and divided by 2 (CPUDIV1). So your CPU is actually running at 48MHz, not 20MHz. 19200/48*20 = 8000.
Change the clock statement to match the real frequency of your CPU, and things should be fine.
The oscillator settings on these chips, are _complex_!...
Best Wishes |
|
|
fabien.casas
Joined: 28 Nov 2006 Posts: 6
|
|
Posted: Wed Nov 29, 2006 11:11 am |
|
|
Ok, thanks John and Ttelmah,
I've taken a closer look at the CPU clock chain.
My external oscillator provides a 24MHz frequency, so I configured
#fuses with:
- HSPLL and USBDIV: because I plan to use USB,
- PLL5: to scale my input frequency down to 4 MHz before the 96MHz PLL, as required,
- CPUDIV1: to scale that 96Mhz frequency down to 48MHz (so the PIC may work...)
I get a CPU frequency of 48MHz.
So I set my "clock" accordingly:
Code: |
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,stream=pc, bits=8, ERRORS)
|
and that worked fine : the final baudrate was 19200 bps.
Thanks again for help!
fabien |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|