Hello,
I wire a crystal 3.579 Mhz on EXTAL and XTAL pins via 2 capacitors and RF resistor.
I want to use it for the bus clock CPU.
First, to test it, I write a code for blinking a LED. It does'nt work in external clock mode. No problem in internal clock mode.
Here the initialization :
I set up ICSC1 like this :
CLKS = 10
RDIV = 000
IREFS=0
IRCLKEN=0
IREFSTEN=0
and ICSC2 like below:
BDIV=01
RANGE, HGO,LP, EREFS =1
ERCLKEN=0
EREFSTEN=0
I am waiting until external reference is stable between ICSC2 and ICSC1 :
while (!ICSSC_OSCINIT){}
Must I set IREFS to 1 because my crystal isn't multiple of 32 Khz ?
Why, when I delete the "while !ICSSC_OSCINIT){}" line, the uC switch in internal clock ?
Thanks for your help.
Herve
Hello Herve, and welcome to the forum.
I my understanding is that you are setting ICSC1 register, and then waitingfor the OSCINIT flag, before setting ICSC2 register. Is this correct?
If so, the crystal will not oscillate because you do not yet have EREFS bit set for compatibility with an external crystal. If you need to monitor OSCINIT, this should be done after both registers ICS1 and ICS2 are setup. I presume that you intend using FBELP mode. I would also be possible to use FBE mode. Note that you will not be able to debug using FBELP mode because the FLL is stopped.
Regards,
Mac
Thanks Bigmac,
In effect, I tested OSC_INIT between ICSC2 and ICSC1 set up.
I tried to test OSC init after the 2 registers initialization, without success.
I tried in FBE mode too (LP =0), to enter in debug mode. the CPU stops at the OSC INIT test.
When I delete the test, the CPU works in internal clock mode, why ?
Perhaps, I have a hardware problem, I will check my crystal and capacitors.
Regards,
Hervé