KL26 Moving from FEI to PEE mode ,running is ok ,but do not debug

cancel
Showing results for 
Search instead for 
Did you mean: 

KL26 Moving from FEI to PEE mode ,running is ok ,but do not debug

Jump to solution
392 Views
chuanchuanli
Contributor I

   I use keil5, I do clock init  .reference: "KL26P121M48SF4RM" of page on 416~418 24.5.3.1 Example 1: Moving from FEI to PEE mode: External Crystal =4 MHz, MCGOUTCLK frequency = 48 MHz

it running is ok ,but when I do debug,it is failed . it stopping " while((MCG->S & IREFST ) == 0x10U);"  I need you help. thanks

external reference clock is 8Mhz

my code as follow

#include "MKL26Z4.h"

#include "clock.h"

#define OSCINIT0 0x02

#define IREFST   0x10

#define CLKST    0x0c

#define PLLST    0x20

#define LOCK0    0x40

void Clock_Init(void)

{

  // SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;

  //CLOCK_SETUP=1;

  SIM->COPC = (uint32_t)0x00u;

  SIM->SCGC5 |= (uint32_t)0x0200UL;       /* Enable clock gate for ports to enable pin routing */

  SIM->CLKDIV1 = (uint32_t)0x00010000UL;  /* Update system prescalers */

  PORTA->PCR[18] &= (uint32_t)~0x01000700UL;

  PORTA->PCR[19] &= (uint32_t)~0x01000700UL;

  OSC0->CR = (uint8_t)0x80U;

    MCG->C2=0x1c;    //

   MCG->C1=0x98;     // MCGLOUTCLK

    while((MCG->S & OSCINIT0 ) == 0x00U);     //

    while((MCG->S & IREFST ) == 0x10U);        /

   while((MCG->S & CLKST ) != 0x08U);        //

   MCG->C5=0x03;

   MCG->C6=0x40;                             //

   MCG->C2=0x1c;

  while((MCG->S & PLLST ) == 0x00U);

  while((MCG->S & LOCK0 ) == 0x00U);

  MCG->C1=0x18;

  while((MCG->S & CLKST ) != 0x0cU);

}

Best regards,

Labels (1)
1 Solution
60 Views
adriancano
NXP Employee
NXP Employee

Hi,

I tested the same on a FRDM-KL26Z and CodeWarrior and found the same behavior. I saw that the behavior is related with the wrong configuration of the MCG_C2 register. In your code you are configuring:

MCG_C2 = 0x1C which is:

RANGE0 = 01 Encoding 1 — High frequency range selected for the crystal oscillator .

EREFS0 = 1  Oscillator requested.

HGO0 = 1 Configure crystal oscillator for high-gain operation.

According to the DataSheet when RANGE0 = 01 the Oscillator must have a value of Min. 3 MHz and Max. 8 MHz. Since I am using the FRDM-KL26Z with an 8 MHz Oscillator I configured:

MCG_C2 = 0x24 which is:

RANGE0 = 1x Very high frequency range selected for the crystal oscillator

EREFS0 = 1  Oscillator requested.

HGO0 = 0 Configure crystal oscillator for low-power operation.

data kl26.jpg

Please check that the MCG_C2 value is configured correctly according to the Oscillator values in your hardware.

Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

3 Replies
61 Views
adriancano
NXP Employee
NXP Employee

Hi,

I tested the same on a FRDM-KL26Z and CodeWarrior and found the same behavior. I saw that the behavior is related with the wrong configuration of the MCG_C2 register. In your code you are configuring:

MCG_C2 = 0x1C which is:

RANGE0 = 01 Encoding 1 — High frequency range selected for the crystal oscillator .

EREFS0 = 1  Oscillator requested.

HGO0 = 1 Configure crystal oscillator for high-gain operation.

According to the DataSheet when RANGE0 = 01 the Oscillator must have a value of Min. 3 MHz and Max. 8 MHz. Since I am using the FRDM-KL26Z with an 8 MHz Oscillator I configured:

MCG_C2 = 0x24 which is:

RANGE0 = 1x Very high frequency range selected for the crystal oscillator

EREFS0 = 1  Oscillator requested.

HGO0 = 0 Configure crystal oscillator for low-power operation.

data kl26.jpg

Please check that the MCG_C2 value is configured correctly according to the Oscillator values in your hardware.

Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

60 Views
chuanchuanli
Contributor I

thank you . and I have some question abot HGO0 .why HGO0 = 0,  low-power or high-gain ,  high-gain have a good ?

QQ截图20150320110317.png

0 Kudos
60 Views
adriancano
NXP Employee
NXP Employee

Hi,

The different HGO modes can be used according to your hardware and project requirements. Please refer to the specific reference manual in the section High-Frequency, High-Gain Mode and section High-Frequency, Low-Power Mode to have a better understanding of each mode. As you can see in the Datasheet in the section Oscillation frequency specifications the HGO modes will impact directly in the Crystal startup time.

osc.jpg


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos