AnsweredAssumed Answered

KL27Z644 HIRC mode

Question asked by Radu Nasui on Jan 4, 2016
Latest reply on Jan 6, 2016 by Kerry Zhou

I have been trying to enable the HIRC MCG mode on a MKL27Z microcontroller. As far as I know, there are at least two ways to do this: to write the code using the device registers or to use KDSK device specific drivers.


For the first approach my could would look like this:


#include "fsl_device_registers.h"

void main(void)


  MCG_MC |= MCG_MC_HIRCEN_MASK; //enable the HIRC


  MCG_C1 |= MCG_C1_CLKS(0b00); //use the HIRC oscillator as the system clock


  for (int i = 0 ; i < 2000 ; i++)

  {if (((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) == 0b00) break; // jump out early if CLKST shows HIRC CLK selected before loop finishes




The problem with this example is that it does not enter the HIRC mode. I have tried the same approach on on enabling other modes and it works. Am I missing something?



The second approach is to use one of the functions provided in the low level HAL driver, fsl_mcglite_hal.h:


static void CLOCK_HAL_SetHircCmd (MCG_Type  *base, bool enable)


Although the latter will mean less lines of code, I cannot find any reference to what possible values I could give to base ( I could not find any reference to MCG_Type type).


Any thoughts??