View previous topic :: View next topic |
Author |
Message |
parthiv2eng
Joined: 17 Jul 2013 Posts: 6
|
[SOLVED] UART and External Clock - PIC18F25k20 |
Posted: Wed Jul 17, 2013 1:08 pm |
|
|
Hi,
I am using pic18f25k20 with external oscillator. The problem is my UART transmit works fine but when it comes to receiving it won't receive proper data or skips data.
If I use internal clock. everything works fine like charm.
Code: |
******************************************************************************/
/*! Include Section: (Library Files)
*/
#include <18F25K20.h>
/*****************************************************************************/
/*! Device bit configuration
*/
#device *=16 ICD=TRUE // Use 16 bit pointers, enable ICD
#device adc=10
#FUSES WDT //WDT128 //NOWDT //Use Watch Dog Timer
#FUSES EC_IO //External Clock
//#FUSES INTRC //Internal RC Osc
#FUSES PROTECT //NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES DEBUG //Debug mode for use with ICD
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
//#use delay(clock=16000000) //clock for the delay 16 MHz
#use delay(osc=3686400) //Assiegn oscillator
//! Initialize UART
#use rs232(baud=115200, parity = o,xmit=PIN_C6, rcv=PIN_C7,errors) //!Initialize UART
|
My external osc frequency 3.6864Mhz and measured using scope. Please guide me. Any comment is appreciated. Thanks!
Last edited by parthiv2eng on Tue Aug 27, 2013 10:39 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed Jul 17, 2013 3:25 pm |
|
|
You just not clocking fast enough.....
3.7MHz. Just 0.925MIPS. 115200bps. One character every 80 instructions. If you are (for instance) using interrupt driven serial, it takes typically 60 instructions, just to get into and out of the interrupt handler. Add the time to store the data (if you are using an array, it takes quite a few instructions to access each location), and you are just running out of time....
Transmit doesn't have a problem, since if the processor can't keep up, there will just be gaps between the characters. Also you are doing the transmit, rather than the characters arriving 'unprompted' as they do on the receive.
If you can lose the OSC1 pin, just select HSPLL, instead of EC_IO, and run at 14745600Hz. Otherwise switch to a faster oscillator.
Best Wishes |
|
|
parthiv2eng
Joined: 17 Jul 2013 Posts: 6
|
|
Posted: Wed Jul 17, 2013 4:08 pm |
|
|
Quote: |
If you can lose the OSC1 pin, just select HSPLL, instead of EC_IO, and run at 14745600Hz. Otherwise switch to a faster oscillator. |
In PIC18F25k20
Fuses: LP,XT,HS,RC,EC,EC_IO,H4,RC_IO,INTRC_IO,INTRC,NOFCMEN,FCMEN
I don't get it how to turn PLL on for External Clock.? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9228 Location: Greensville,Ontario
|
|
Posted: Wed Jul 17, 2013 6:48 pm |
|
|
Can you also confirm that you need 'odd' parity ? Most 8 bit UART data transfers have 'none' selected for parity.
Having the wrong parity could cause 'data problems'.
I know some products have 'interesting' or 'nonstandard' settings, just thought I'd ask.
hth
jay |
|
|
parthiv2eng
Joined: 17 Jul 2013 Posts: 6
|
|
Posted: Wed Jul 17, 2013 10:00 pm |
|
|
temtronic,
Thanks for reply. The problem is data receiving by UART using "External Clock". When I use internal clock everything seems working fine. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Jul 18, 2013 12:43 am |
|
|
H4
However this will switch to HS PLL (*4), not 'external clock'. Generally it'll work fine with a clock fed into the input pin (though you may need to add a series resistor to avoid over-driving the input). However you lose the oscillator output pin.
Best Wishes |
|
|
parthiv2eng
Joined: 17 Jul 2013 Posts: 6
|
|
Posted: Mon Jul 29, 2013 4:33 pm |
|
|
Thanks Ttelmah,
Still it won't work.. |
|
|
parthiv2eng
Joined: 17 Jul 2013 Posts: 6
|
|
Posted: Tue Aug 27, 2013 10:39 am |
|
|
Sorry for Late reply,
Ttelmah, It's working with H4 using external clock.
Thank you all |
|
|
|