AnsweredAssumed Answered

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

Question asked by chuanchuan li on Mar 17, 2015
Latest reply on Mar 23, 2015 by Adrian Cano

   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,

Outcomes