Hi Kan,
Thanks for your reply, you were right, I didn't enable the interrupt and didn't clear the TFC flag. You ment TFC, not TCF, yeah? Because, according to reference manual, TFC flag is responsible for CNR reset, not TCF.
But there is still no luck and CNR is still remains zero =(
Here is the full code:
unsigned int compare_value = 1000;
serial.baud(115200);
__enable_irq();
NVIC_EnableIRQ(LPTimer_IRQn);
/* Clock the timer */
SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK;
/* reset the counter */
LPTMR0->CSR &= ~LPTMR_CSR_TEN_MASK;
/* turn on portc */
SIM->SCGC5 |= SIM_SCGC5_PORTC_MASK; //Turn on PORTC clock
PORTC->PCR[5] = PORT_PCR_MUX(0x4); //Use ALT2 on PTC5
LPTMR0->PSR = LPTMR_PSR_PCS(3) | LPTMR_PSR_PBYP_MASK; //Use LPO clock but bypass glitch filter
LPTMR0->CMR = LPTMR_CMR_COMPARE(compare_value); //Set compare value
/* set pulse mode */
LPTMR0->CSR = LPTMR_CSR_TPS(0x2) | LPTMR_CSR_TMS_MASK; //Set LPT to use the pin selected, and put in pulse count mode, on rising edge (default)
/* disable timer compare */
LPTMR0->CSR &= ~LPTMR_CSR_TFC_MASK;
/* Enable interrupt */
LPTMR0->CSR |= LPTMR_CSR_TIE_MASK;
/* start pulse counter */
LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;
while(1) {
if(LPTMR0->CNR != 0)
printf("Current value of pulse count register CNR is %d\r\n", LPTMR0->CNR);
}
Didn't I miss something?