LPTMR interrupt not working

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

LPTMR interrupt not working

2,450 Views
vinkar
Contributor III

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
Labels (1)
Tags (2)
8 Replies

1,426 Views
vinkar
Contributor III

It is a KL04 kinetis chip.

0 Kudos

1,426 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Vinod:

Are you declaring the ISR in the interrupt vectors table?

You do not mention what device you are using, but the attached project is a LPTMR example for KL25 using CodeWarrior. You can see the vectors table in the file kinetis_sysinit.c.


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,426 Views
vinkar
Contributor III

Hello Jorge,

Thank you for the quick response.

I am using the default interrupt handler.

Shouldnt that be ok for interrupts.

Or should I again declare

void LPTimer_IRQHandler(void) in the kinetis_sysinit.c file.

Vinod.

0 Kudos

1,426 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hi Vinod:

What do you mean by "...using the default interrupt handler"? Do you mean the same name?

I just copied your exact same code to a new project with KL05 and the interrupts are firing OK. I suppose you are using CodeWarrior.


Regards!,
Jorge Gonzalez

0 Kudos

1,426 Views
vinkar
Contributor III

Hello Jorge,

Yes, I am using the same name.

This is really weird. I am testing this code on an old board it works.

But in the new board it does not go into the ISR. The hardware schematic is the same no change.

In the new board the code can be burnt. Pin toggling works fine. Interrupts r not working for some

unknown reasons.

Also, I disabled the interrupts as a test to see if the pin toggles with just the LPTMR timeout. It does that.

So, I think its an interrupt issue. Also, i tried interrupts for the TPM0 and TPM1, none work. So its clearly an

interrupts based issue. Have you noticed such a bug before. All the said interrupts work in my old hardware.

BTW, I am using

CodeWarrior for MCU

     Version: 10.6

     Build Id:140329

How can I am attaching my project (complete) to this discussion.

Vinod.

He
0 Kudos

1,426 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello vinod:

Sorry I did not reply, there are a lot of questions and it is hard to keep track.

Are you still having issues with interrupts? It could be caused by the NMI pin. Check that this pin is not being pulled low during MCU power on. If possible place a pull-up resistor to force a high level.

Regards!

Jorge Gonzalez

1,426 Views
vinkar
Contributor III

It Worked Jorge.

Thank u very much indeed.

0 Kudos

1,426 Views
vinkar
Contributor III

Hello Jorge

I have connected that pin to adc facility. I am using the 24 pin kl04. So pin 19 has nmi_b. This might not be the reason as in my previous hardware also I did not give a pull up. I think u may be wrong on this. Also , this pin has pull up (internal) at POR. Also, what is the actual function of the nmi_b pin. I am able to program the chip ,toggle pins ...etc.

What is surprising is that in my previous hardware I did not have any pull ups whatso ever,yet, all interrupts worked fine. Also, if I have pullups it will corrupt my ADC readings.

Another point, I was looking at the frdm board schematics. It uses the KL05 32 pin chip. The nmi_b is not pulled up in it as well. There is no pull up in that board as well. The circuit is attached with this answer.

Vinod.

0 Kudos