|
|
View previous topic :: View next topic |
Author |
Message |
Fabri
Joined: 22 Aug 2005 Posts: 275
|
USB to RS485 Converter with PIC18F2455 |
Posted: Wed Aug 22, 2007 10:04 am |
|
|
Hi To All,
I'm working on USB to 485 converter based on ex_usb_serial.c example.
There's no problem with UART baudrate of 9600 or more but the compiler give me Baud rate error when I set to speed to 2400. This happend with hardware UART, there's no problem with FORCE_SW option.
I use crystal of 16Mhz and this settings:
Code: | #fuses HSPLL,WDT,PROTECT,NOLVP,NODEBUG,USBDIV,PLL4,CPUDIV1,VREGEN,BROWNOUT_NOSL
#use delay(clock=48000000) |
What I need to change to use hardware UART with 16 Mhz crystal ?
Regards,
Fabri |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Wed Aug 22, 2007 10:19 am |
|
|
Code: | #use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,stream=rs232)
|
The pins are the RX and TX pins connected to hardware UART. The line above is for 16F88. The pins can be different in your case.
By the way, it looks like you're overclocking the PIC. The maximum clock rate is 40MHz (after PLL). _________________ Read the label, before opening a can of worms. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Wed Aug 22, 2007 11:08 am |
|
|
kender wrote: | The maximum clock rate is 40MHz (after PLL). |
Some of the new chips with a USB port can go 48Mhz. The PIC18F2553 can go that fast and it has 12-bit ADC as well.
The baud rates that the hardware can support is related to the crystal speed. It may be that you have to run the crystal slower to support the lower baud rates. You should look to find this kind of information in the datasheet. |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Thu Aug 23, 2007 12:16 am |
|
|
Hi,
I supposed to use slow frequency crystal.
Thanks for help.
Regards,
Fabri |
|
|
Ttelmah Guest
|
|
Posted: Thu Aug 23, 2007 4:45 am |
|
|
This gets more complex than it appears.
On these chips, the baud rate, is _not_ directly determined by the crystal frequency. Instead it is determined by the CPU 'core' frequency, which can be derived from a whole series of sources (internal oscillator, secondary oscillator on T1, the USB PLL, or directly through a frequency divider from the master clock), while the crystal is at a different rate in many cases. The 'Fosc' used by the UART, is the line marked 'peripherals', coming out the right hand side of the clock diagram.
Then the available dividers are larger than on the older chips.The BRG, supports 16bit operation, and there is a /64 prescaller, as well as the normal /4, and /16 values. This allows (with the 48MHz maximum clock), rates down to 11.44bps...
What matters though, is the compiler version. The latest compilers 'know about' the extra features of the UART on these chips (4.051, compiles the USB sample, with the hardware UART rate set to 100bps fine), while 3.249, will complain about the baud rate range.
One answer, is to select a higher rate, and write a simple function to enable the 16bit divider yourself.
Best Wishes |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Thu Aug 23, 2007 8:48 am |
|
|
Thanks Ttelmah for explain me how compiler work.
My compiler version is 3,349 and, at the moment, I don't think to upgrade it to new version. I forced PIC to software UART and all work fine. I'll work around in second time.
Regards,
Fabri |
|
|
|
|
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
|