AnsweredAssumed Answered

LPTMR0 activation on FRDM-KL03Z board

Question asked by Beau Rogers on Jul 31, 2017
Latest reply on Aug 3, 2017 by Mark Butcher

Hello, I have been trying for a very long time to try and get the Low Power Timer going on the FRDM-KL03Z board and have had no luck. I have been trying to find where the 32k crystal is being output to but I can't see the signal nor can I measure continuity to the pin. As EXTAL is not on the developement board, I would assume it would output to the RTC_CLK_IN pin (PTA5) My code is seen below:


////////////////////Port Set up/////////////////////////////
PORT_BWR_PCR_MUX(PORTA, 5, 0b001); //Set the Alt1 muxing on Port A, pin 5 for RTC_CLK_IN (SiT1532_OUT) (32 kHz clock)
GPIO_SET_PDDR(GPIOA, 0U<<5); //Set PORTA pin 5 to input


///////////////////////////////////////////////LPTMR initialization///////////////////////////////////////////////////

SIM_BWR_SCGC5_LPTMR(SIM_BASE_PTR, 1); //enabling software access to low power timer module
SIM_BWR_SOPT1_OSC32KSEL(SIM_BASE_PTR,0b00); //Selects the clock source (ERCLK32K) for LPTMR (00), RTC_CLKIN (10)
SIM_BWR_SOPT1_OSC32KOUT(SIM_BASE_PTR,0b01); // (01)Set the clock ERCLK32K output on pin13
SIM_BWR_SOPT2_CLKOUTSEL(SIM_BASE_PTR,0b110); // Clock to output on the CLKOUT pin (110) OCERCLK

MCG_BWR_C2_EREFS0(MCG, 1); //Selects the source for the external reference clock to be external clock.
MCG_BWR_C2_IRCS(MCG,1); //Selects LIRC to 8Mhz
OSC_BWR_CR_ERCLKEN(OSC, 1); //Enables the external reference clock (OSCERCLK)

MCG_BWR_C1_CLKS(MCG, 0b10); //Selects external clock as the main clock source. This is EXT mode

//Set-up the LPTMR
//Set the LPTMR PSR Register
LPTMR_BWR_CSR_TEN(LPTMR0, 0); //LPTMR is disabled
LPTMR_BWR_PSR_PCS(LPTMR0, 0b10); //Sets LPTMR clock to MCGIRCLK (00), LPO Timer (01), ERCLK32K (10)
LPTMR_BWR_PSR_PBYP(LPTMR0, 0); //(1) LPTMR prescale is disabled
LPTMR_BWR_PSR_PRESCALE(LPTMR0, 0b0000); //Sets the prescale to divide by 2

// Set the LPTMR Working Mode for Time Counter
LPTMR_BWR_CSR_TMS(LPTMR0, 0); // Sets the mode to Time counter (0) or Pulse counter (1)
LPTMR_BWR_CSR_TFC(LPTMR0, 1); // Set the CNR to reset on overflow (1), reset when TCF is set (0)

tick_count=49151; //3s with freq=32768, ps=2

LPTMR_BWR_CMR_COMPARE(LPTMR0, tick_count); //Sets the compare value that will trigger TCF to be set when CNR matches CMR

//Initialize the LPTMR interrupt
LPTMR_BWR_CSR_TIE(LPTMR0, 1); //Enable the timer interrupt (1)


//////////////////////////////////////////////////////Interrupt Routine////////////////////////////////////////////////////////

void LPTMR0_IRQHandler(void)
LPTMR_BWR_CSR_TCF(LPTMR0, 1); //Clear the interrupt flag
GPIO_WR_PTOR(GPIOB, 1U<<2); //Toggle pin2 on PortB to turn on an LED RED




Any help would be much appreciated, thank you.