|
|
View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
How to set the baud rate using INTRC_IO and H4 |
Posted: Tue Oct 18, 2011 11:49 pm |
|
|
Hi,
I have configured a 18F2620 using these fuse settings..
Code: |
#include <18F2620.h>
#fuses INTRC_IO,H4,NOWDT,PUT,NOPROTECT,NOMCLR,NOCPD,BROWNOUT,NOLVP,NOPBADEN,NOIESO,NOFCMEN
#use delay(clock=4000000)
#use rs232(baud=19200,xmit=pin_c6, rcv=pin_c7,parity=n,brgh1ok)
|
The PIC is working alright, but I cannot get the serial port to work, the serial port works with INTRC_IO without the H4 setting..
Please suggest how the serial port can be configured....
Setting a higher baud rate (at 115200) generates a error..
thanks
a |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Wed Oct 19, 2011 5:27 am |
|
|
Looks like your fuses aren't the correct ones.
You can't get 115200 baud with a 4MHz Internal oscillator as you've chosen the 'HS' fuse.'HS' refers to an external crystal,'INTRC_IO' means use the internal osc. section and 'free up' 2 pins for I/O functions.
Try using the 'HSPLL', which should enable the PLL and turn the 4MHz INTOSc into a 16 MHz clock.At that speed, 115200 baud should be possible.
Consult the datasheet sections on 'oscillator configurations' as well as 'UART options'. The diagrams and charts are easy to understand the 'flow' and how it works.
These newer PICs are full of options and as I found out, you have to read the datasheet a few times, to get the correct setup. |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Fri Oct 21, 2011 11:55 pm |
|
|
Quote: | You can't get 115200 baud with a 4MHz Internal oscillator as you've chosen the 'HS' fuse.'HS' refers to an external crystal,'INTRC_IO' means use the internal osc. section and 'free up' 2 pins for I/O functions. |
Any other baud rate would be suitable, I normally use 9600, even this would be OK. I would prefer to use the internal oscillator as this would reduce part count.
In the datasheet, 'Internal Oscillator Block' , 2.6.4..section mentions that it should be possible to run the PIC at 32 MHz using PLL with the internal oscillator..
So how do I configure this in PCH, do I have to access the OSCCON and OSCTUNE registers directly ??
So tips would be appreciated here...
Note: Any suitable baud rate would be acceptable as this is not essential for the working of my system, I just need a serial port for debugging purposes..
thanks
a |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sat Oct 22, 2011 3:41 am |
|
|
You don't need to fiddle with anything directly. Just use:
Code: |
#include <18F2620.h>
#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOMCLR,NOCPD,BROWNOUT,NOLVP,NOPBADEN,NOIESO,NOFCMEN
#use delay(clock=32MHZ)
#use rs232(baud=115200,xmit=pin_c6, rcv=pin_c7,parity=n,ERRORS)
//BRG10K, is _only_ for chips that have the BRG fault
//If you use the hardware UART, you should _always_ have
//ERRORS, unless you add your own error handling code - omitting this
//can leave the UART hung if certain errors occur....
//Then in main
void main(void) {
//Variable declaraitions
setup_oscillator(OSC_32MHZ);
//other setup and code
}
|
Key thing is to study the clock diagram. The 'H4' PLL (fuse settable), is _not_ available for the internal oscillator. When you use the internal oscillator, you have a _software_ switchable PLL available, which (obviously) requires code to enable it!.
Now, depending on your compiler version, selecting 'INTRC', or 'INTRC_IO', and specifying the clock as 32MHz, should do this automatically, however. setup_oscillator 'makes sure'.....
Best Wishes |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Sat Oct 22, 2011 5:28 am |
|
|
Thanks a lot, it works perfectly now..
thanks
a |
|
|
|
|
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
|