11 years ago.  This question has been closed. Reason: Duplicated

How do I access the KL25Z internal clock registers?

Can anyone help with Mbed code to route the 32KHz internal reference oscillator to the RTC Clock Input. I have found some information on the Freescale web site where someone has done this using Code Warrior.

https://community.freescale.com/message/308994#308994

The idea is to route the 32KHz ref osc out on pin PTC3 and connect this to pin PTC1 as below:

•set RTC Clock Input to "Enabled". This sets PTC1 as an input for a clock source.

•set MCGIRCLK source to "slow" in "Clock Source Settings" > "Clock Source Setting 0" > "Internal Reference Clock"

•set ERCLK32K Clock Source to "RTC Clock Input" in "Clock Source Settings" > "Clock Source Setting 0" > "External Reference Clock"

•Enable "CLKOUT pin control" in "Internal Peripherals" > "System Integration Module"◦set "CLKOUT pin" to "PTC3/LLWU_P7/..." ◦Set "CLKOUT pin output" to "MCGIRCLK"

◦This routes the internal 32K reference oscillator out to pin PTC3

On the RTC, set the "Clock Source" to "ERCLK32K".

..........Further to this someone has suggested this:

  • Clock Generator generates wave on PTD1,
  • the frequency is set up by CLOCK_PERIOD constant,
  • the wave is symmetric 50/50.

void clockGenerator(void)

{ 0.000030517578125 = 1/32768

#define CLOCK_PERIOD (1/(2^15))

  1. define CLOCK_PERIOD (0.000030517578125)

#define CLOCK_PERIOD (0.01) <- 100Hz

PwmOut out(PTD1); /* PTD1 is the same address as LED1 */

out.period(CLOCK_PERIOD); out requires a 2ms period

out.pulsewidth((CLOCK_PERIOD/2)); out position determined by a pulsewidth between 1ms }

..............I do not know how to access the resisters for the KL25Z. I have written similar code to access the spare RTC registers using this I found from another Mbed member and it works.

LPC_RTC->GPREG0 = tz; (to store the variable tz)

tz=LPC_RTC->GPREG0; (to read back to the variable tz)

...............So I'm hopping to be able to control the clock generator registers in a similar way to give me a 32kHz without using an external source.

Any suggestions would be helpful.

Thank you

1 Answer

10 years, 11 months ago.

See this file: http://mbed.org/users/mbed_official/code/mbed-Freescale/file/d5f2f3e8f628/cmsis/KL25Z/MKL25Z4.h

It is some searching around, the RTC registers are defined around lines 2615. Then it is a bit different than the NXP cmsis, but at 2729 the RTC's base name is defined, as a not very original 'RTC'. So for example you got RTC->SR = 0; (Sets the status register to 0).