KL03Z: How to see the 1Hz RTC Clock on RTC_CLKOUT?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KL03Z: How to see the 1Hz RTC Clock on RTC_CLKOUT?

766 Views
sarastout-grand
Contributor III

Hello,

I've been trying unsuccessfully to get the 1Hz RTC clock to appear on PTB13, the RTC_CLKOUT pin.

Here is what I am doing to set-up the RTC and clocks to enable this to happen:

// (01)Set the clock ERCLK32K output on pin13, (00) clock not output

SIM_BWR_SOPT1_OSC32KOUT(SIM_BASE_PTR,0b00);

 // Enable access and interrupts for RTC

SIM_BWR_SCGC6_RTC(SIM_BASE_PTR, 1);
// Enable a clock for the RTC so it can output the 1Hz clock, OSC32KCLK (00), LPO(11), RTC_CLKIN (10) 

SIM_BWR_SOPT1_OSC32KSEL(SIM_BASE_PTR, 0b11);

//Selects the RTC 1Hz (0) or OSCERCLK (1) Clock for output on RTC_CLKOUT pin

SIM_BWR_SOPT2_RTCCLKOUTSEL(SIM_BASE_PTR, 0);

//Enable the time counter

RTC_SR=0b00000000000000000000000000010001;

//Enable the port

PORT_BWR_PCR_MUX(PORTB, 13, 0b011); //Set the Alt3 muxing on PortB, pin 13 for RTC_CLKOUT
GPIO_SET_PDDR(GPIOB, 1U<<13); //Set PORTB pin 13 to output

This does not work, I get a flat line on PTB13. I have played with the sequence of some of these commands, like enabling the time counter RTC_SR after the port definition, but no change. If I change the RTCCLKOUTSEL to 1, I do see the correct signal on PTB13. I am puzzled! Is there something I'm missing?

Also, what is the meaning of "Pad Interface" in Figure 5-4 from the user's manual?

pastedImage_1.png

Thanks,

Sara

Labels (1)
Tags (4)
0 Kudos
1 Reply

547 Views
mjbcswitzerland
Specialist V

Hello Sara

As long as you have the RTC operating the only thing needed to output RTC_CLKOUT (1Hz) is to select ALT3 use of PTB13.
I do it like this:

_CONFIG_PERIPHERAL(B, 13, (PB_13_RTC_CLKOUT | PORT_SRE_SLOW | PORT_DSE_LOW));

which equates to
1. Enable clocks to port B
2. Set PTB13 to ALT3 function

You don't need to set the DDR since it is not used for peripheral functions.

If you get no output it is likely to be that the RTC is not operating.

Attached is a binary file that you can load to the FRDM-KL03Z which outputs the clock. Use a debugger to check the registers and compare to yours.

Regards

Mark

P.S. The PAD thing has to do with the fact that PTB13 GPIO and CLKOUT32K are shared. You can ignore it when using RTC_CLKOUT (ALT3 peripheral functions).

0 Kudos