RTC clock out configuration (RTC_CLKOUT)

Document created by Iliana Berenice Tejeda Hernandez Employee on Mar 3, 2016
Version 1Show Document
  • View in full screen mode

I´m going to explain how configure the RTC_CLKOUT pin and the different outputs that you can get with the KW40Z board. First it must be clear that the next configuration are based to use any demo of the KW40Z_Connectivity_Software_1.0.1 and also must to use the IAR Embedded Workbench.

Now that you have all the software installed follow the next instructions.

 

Configure the pin

In the Reference Manual you will realize that each pin has different ways to configure it, in our case the pin that we are going to use is the PTB3 with a MUX = 7. The mux 7 is the RTC_CLKOUT.

 

 

Figure 1. PTB3 mux configuration

The KSDK have many functions that initializes the ports and the different peripherals.
The configure_rtc_pins() function initialize the RTC_CLKOUT pin, you can find it in the pin_mux.h file. You must add the two functions in the hardware_init() function, that is declared in hardware_init.c file.
The hardware_init() function must be like show next:

void hardware_init(void) {     ...
     ...
     NV_ReadHWParameters(&gHardwareParameters);
configure_rtc_pins(0);
}

 

Enable the RTC module.

Now that the pin is already configure, you have to initialize the RTC module and the 32 KHz oscillator.

You must understand that the RTC module can work with different clock sources (LPO,EXTAL_32K and OSC32KCLK) and it can be reflected through the RTC_CLKOUT pin. The register that change the clock source is the SIM_SOPT1 with OSC32KOUT(17-16) and OSC32KSEL(19-18) these are the names of the register bits.

 

The OSC32KOUT(17-16) enable/disable the output of ERCLK32K on the selected pin in our case is the PTB3. You can configure with two options.

00     ERCLK32K is not output.

01     ERCLK32K is output on PTB3.

 

The OSC32KSEL(19-18) selects the output clock, they have 3 option like show in the next image.

Figure 2. Mux of the register SIM_SOPT1

 

The follow table show the different outputs that you can get in the RTC_CLKOUT pin, you only have to modify the OSC32KOUT and OSC32KSEL in the register SIM_SOPT1.

Figure 3. Output of RTC_CLKOUT pin.

 

Like the configuration of the pin, KSDK have function that initialize the RTC module and the 32 KHz oscillator.

The RTC_DRV_Init(0) function initialize the RTC module and is declared in fsl_rtc_driver.h file, the BOARD_InitRtcOsc() function enable the RTC oscillator and is in the board.h file, the RTC_HAL_EnableCounter() enable the TCE(Timer Counter Enable) that is in the fsl_rtc_hal.h file and finally the SIM_SOPT1_OSC32KOUT() enable/disable the ERCLK32K for the RTC_CLKOUT(PTB3) and SIM_SOPT1_OSC32KSEL() selects the output clock.

To enable the RTC module copy the next code:

 

RTC_Type *rtcBase = g_rtcBase[0];//The RTC base address 
BOARD_InitRtcOsc();
RTC_DRV_Init(0);
RTC_HAL_EnableCounter(rtcBase, true);
SIM_SOPT1 = SIM_SOPT1_OSC32KOUT(0)|SIM_SOPT1_OSC32KSEL(0);
     //Your RTC_CLKOUT is 1Hz with this configuration

 

NOTE: Don’t forget to add the header necessary in the file that you are using.

 

Enjoy it!

Attachments

    Outcomes