AnsweredAssumed Answered

External crystal clock on MKW22 MCU not working

Question asked by Matthieu Remacle on Nov 30, 2017
Latest reply on Dec 7, 2017 by Matthieu Remacle

Hello everybody,

 

I'm desperately trying to use a 32 MHz external crystal oscillator on the MKW22 Kinetis MCU (so using PEE mode).

 

When I do that, I sometimes get stuck when waiting for MCG->S OSCINIT0 value to be set. The wierdest part is that I always get stuck when using a certain processor, and it always works perfectly when using another (with the exact same reference !). Some random behaviour is observed but it's impossible for me to undersand from where it comes.

 

The external crystal is placed between XTAL_32M and EXTAL_32M pins.

 

So fare, I tried it on 5 different processors, it worked for 3 of them and I didn't for the other 2). It is not useful to accuse the hardware, the boards I'm using where soldered by a professional company and checked after production.

 

A last important detail: We use 802.15.4 protocol on these processors, based on the same external 32 MHz crystal, and this protocol works fine with all processors tested. The problem really seems to come from processor configuration.

 

Here is the code I use to setup my clock:

 

     MCG->C2 = 0x24;

     for(i = 0; i<100; i++)
          __asm__ volatile ("NOP");

     MCG->C1 = 0xA8;

     while(!(MCG->S & MCG_S_OSCINIT0_MASK))
            ;

     while(MCG->S & MCG_S_IRCST_MASK)
          ;

     while(((MCG->S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0b10)
          ;

     __asm("NOP");

     MCG->C5 = 0b00011;

     for(i = 0; i<100; i++)
          __asm__ volatile ("NOP");

     MCG->C6 = 0x50;

     while((MCG->S & MCG_S_PLLST_MASK) == 0)
          ;

     while((MCG->S & MCG_S_LOCK0_MASK) == 0)
          ;

     __asm("NOP");

     MCG->C1 = 0x28;

     while(((MCG->S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0b11)
          ;

 

When this code is executed, on some precessors I never have the condition 

(MCG->S & MCG_S_OSCINIT0_MASK) == 1

but on other processors, this condition is true after some milliseconds.

 

The code above is written based on the following example found in the reference manual (Example 1: Moving from FEI to PEE mode: External Crystal = 4 MHz, MCGOUTCLK frequency = 48 MHz):

 

Is it a problem with the configuration of the oscillator (a external capacitance issue, or the RANGE0 register that does not have the expected value) ? I'm really tired of configuring this clock.

 

Why does NXP creates such hard-to-configure and bug-full features as this MCG module ? It makes me regret the processor choice at the beginning of this project...

 

Thank you for your help,

Best Regards,

Matthieu.

Outcomes