Hello Friends,
I am toggling a pin using the LPTMR. When there is a timeout of the LPTMR, it will be interrupted and thereby toggle a pin.
the code is as stated below
#include "derivative.h" /* include peripheral declarations */
void LPTimer_IRQ(void);
int main(void)
{
int count;
uint16_t countTemp = 0;
asm(" CPSIE i");
MCG_C1 |= 0x02;
SIM_SOPT1 = 0;
SIM_SCGC5 |= (SIM_SCGC5_LPTMR_MASK | SIM_SCGC5_PORTB_MASK);//PORTC_PCR1 |= PORT_PCR_MUX(1);//select RTC_CLKIN function
PORTB_PCR3 |= 0x00000100; // alternative pin mux selection //
GPIOB_PDDR |= 0x00000008; // pin direction //
PORTB_PCR4 |= 0x00000100; // alternative pin mux selection //
GPIOB_PDDR |= 0x00000010; // pin direction //
NVIC_ICPR = 1 << (28);
NVIC_ISER = 1 << (28);
SIM_SCGC5|=SIM_SCGC5_LPTMR_MASK;
/* Reset LPTMR settings */
SIM_SOPT1 = 0;
SIM_SCGC5 |= (SIM_SCGC5_LPTMR_MASK | SIM_SCGC5_PORTB_MASK);//PORTC_PCR1 |= PORT_PCR_MUX(1);//select RTC_CLKIN function
LPTMR0_CSR=0;
LPTMR0_CSR |= 0x00000040;
LPTMR0_CMR = 600;
GPIOB_PTOR |= (1 << 3);
GPIOB_PTOR |= (1 << 4);
GPIOB_PTOR |= (1 << 3);
GPIOB_PTOR |= (1 << 4);
/* Start the timer */
LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;
/* Wait for counter to reach compare value */
asm("nop");
while(1){
// if((LPTMR0_CSR & 0x00000080) == 0x00000080){
// LPTMR0_CSR &= ~LPTMR_CSR_TEN_MASK;
// LPTMR0_CSR |= 0x00000080;
// LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;
// GPIOB_PTOR |= (1 << 3);
// GPIOB_PTOR |= (1 << 4);
// }
}
}
void LPTimer_IRQHandler(void){
if((LPTMR0_CSR & 0x00000080) == 0x00000080){
LPTMR0_CSR &= ~LPTMR_CSR_TEN_MASK;
LPTMR0_CSR |= 0x00000080;
LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;
GPIOB_PTOR |= (1 << 3);
GPIOB_PTOR |= (1 << 4);
}
// LPTMR0_CSR &= ~LPTMR_CSR_TEN_MASK;
// LPTMR0_CSR |= LPTMR_CSR_TCF_MASK;
// GPIOB_PTOR |= (1 << 3);
// GPIOB_PTOR |= (1 << 4);
// LPTMR0_CSR |= LPTMR_CSR_TEN_MASK;
}
But it does not go to the ISR (interrupt service routine).
The timer is turning on as I checked it in the non interrupt way.
Can anyone assist me pls.
Vinod.
Hhelo'[knbkjnbkjb