LPTMR dont work for a delay shorter than 299ms

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

LPTMR dont work for a delay shorter than 299ms

Jump to solution
1,305 Views
paljano
Contributor II

Hello Community,

I have some problems with a kinetis mk10d7. I like to go into stopmode and use the interrupt of the LPTMR to wake up the processor. Behind every wake up the processor should send a char over the UART. Everything works nice when I use a timervalue that let the LPTMR generate a interrupt longer as 299ms. I tryed the LPO and the IRCLK as clock for the LPTMR. It will be nice when you can look on my code. I dont know what the problem is. Thx

#include "derivative.h" /* include peripheral declarations */

#include "driver.h"

int main(void)

{

 

     

    UART_init(115200,9000);                            // baud rate=115200,UART_clk~9MHz

    LPTMR_init(299);                                // init LPTMR 500ms        437

 

    SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;

    SMC_PMCTRL |=  SMC_PMCTRL_STOPM(0);

 

    //Send data     

    for(;;)

    {

        enter_stopmode();

        while(!(UART0_S1 & UART_S1_TDRE_MASK)){};

        UART0_D    =    'a';

    }

    return 0;

}

#include "derivative.h"

//Device inits

void UART_init(unsigned short baud,unsigned int uartclk_khz)

{

    unsigned short sbr,brfa;

    //Initialisation

    SIM_SCGC4    |=    SIM_SCGC4_UART0_MASK;

    SIM_SCGC5    |=    SIM_SCGC5_PORTB_MASK;                                    // Activate clock for PortC

    PORTB_PCR16    =     PORT_PCR_MUX(3);                                        // Set PortB 16 for UARC

    PORTB_PCR17    =     PORT_PCR_MUX(3);                                        // Set PortB 17 for UARC

      

    sbr            =    (unsigned short)((uartclk_khz*1000)/(baud*16));

    UART0_BDH    =    (unsigned char)((sbr & 0x1F00)>>8);                        // Write high word of baud rate into register

    UART0_BDL    =    (unsigned char)(sbr & 0x00FF);                            // Write low word of baud rate into register

  

    brfa        =    (((uartclk_khz*32000)/(baud*16))-(sbr*32));

    UART0_C4    =    (unsigned char)(brfa & 0x001F);                            // Write divider into register 

    UART0_C1    =    0;                                                        // 8-Bit-Mode,No parity

    UART0_C2    |=    (UART_C2_TE_MASK | UART_C2_RE_MASK );                    // Enable receiver and transmitter

}

void LPTMR_init(int timer)

{

    SIM_SCGC5    |=    SIM_SCGC5_LPTIMER_MASK;                                    // Set clock to LPTMR

  

    LPTMR0_CSR=0x00;

    LPTMR0_PSR=0x00;

    LPTMR0_CMR=0x00;

  

    MCG_C1|=MCG_C1_IRCLKEN_MASK;

  

    LPTMR0_CMR    =    timer;                                                    // Set counter

    LPTMR0_PSR    |=    LPTMR_PSR_PBYP_MASK                                        // Prescaler is bypassed

                |    LPTMR_PSR_PCS(1);                                        // Set timer source 0=IRCLK,1=LPO

    LPTMR0_CSR    |=    LPTMR_CSR_TIE_MASK;                                        // Enable interrupt

  

    NVICICPR2    |=    (1<<21);                                                   //Clear any pending interrupts on LPTMR

    NVICISER2    |=    (1<<21);                                                   //Enable interrupts from LPTMR module

    NVICIP85    =    0x10;                                                      //Set Priority 3 to the LPTMR module

  

    LPTMR0_CSR    |=    LPTMR_CSR_TEN_MASK;                                        // activate LPTMR

  

}

//Enter power modes

void enter_stopmode()

{

    volatile unsigned int dummyread;

    dummyread = SMC_PMCTRL;

    SCB_SCR    |=    SCB_SCR_SLEEPDEEP_MASK;

    asm("WFI");

}

My ISR:

void lptmr_irq(){

    LPTMR0_CSR|=LPTMR_CSR_TCF_MASK;

}

Labels (1)
0 Kudos
Reply
1 Solution
808 Views
paljano
Contributor II

Hello Jingjing,

I´ve solved the problem already. I changed the MCU and anythink was fine. The MCU had a defekt.

Best regards,

Eric

View solution in original post

0 Kudos
Reply
3 Replies
808 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Eric Paljan,

     Could you tell me what do you mean LPTMR don't work for a delay shorten than 299ms?

     Is your stop mode can't wake up?  please give me more details about your question.

     Did you test your consumption when you have problem?

     By the way, please tell me the full name of your chip.

Waiting for your reply!

Best regards,

Jingjing

0 Kudos
Reply
809 Views
paljano
Contributor II

Hello Jingjing,

I´ve solved the problem already. I changed the MCU and anythink was fine. The MCU had a defekt.

Best regards,

Eric

0 Kudos
Reply
808 Views
kerryzhou
NXP TechSupport
NXP TechSupport

  OK, that's good!

  If you still have question, you still can let me know!

Best regards,

Jingjing

0 Kudos
Reply