AnsweredAssumed Answered

Weakup from LLS failed,it resets every time

Question asked by stephenkung on Jul 7, 2013
Latest reply on Jul 8, 2013 by stephenkung

Hi,

I'm working with KL25 on freedom board.I have a question about LLWU module and enter-exit from LLS mode.

I have written 3 projects to weakup my mcu from lls mode.I tried with the TSI ,LPTMR and the external pin ,using them as the source of LLWU.But the outcom is the same.Every time,when the interrupt happened ,the MCU will reset.

Here is the simplest one.Using the extern pin as the source of LLWU:

void LLWU_Init(void);

uint8 llwu_wake_up_flag=0;   //the flag of weekup

int main()

{

  uart_init(UART1_BASE_PTR, 24000, 9600);

  GPIO_Init(PORTC, 16, GPIO_OUTPUT, 0);   //led on

  GPIO_Init(PORTC, 3, GPIO_INPUT, 0);   //the souce of LLWU is a gpio input  button

  uart_putchar( UART1_BASE_PTR,'W');    //send a char

  LLWU_Init();

  while(1)

  {

   enter_lls();

   if(key_weakup==1)    //weak up form LLS

  {

   GPIO_SetBit(PORTC,16);   //led off

   Delay1Us(20000);

   uart_putchar( UART1_BASE_PTR,'Y');

   }

   else

   {

    Delay1Us(20000);

    uart_putchar( UART1_BASE_PTR,'N');

   }

  }

}

 

 

void LLWU_Init(void)

{

    enable_irq(LLWU_irq_no);

   llwu_configure(0x0080, 0x02, 0x00);    // External input enabled as falling edge detection

}

 

void enter_lls(void)

{

  volatile unsigned int dummyread;

  /* Write to PMPROT to allow LLS power modes this write-once

     bit allows the MCU to enter the LLS low power mode*/

  SMC_PMPROT = SMC_PMPROT_ALLS_MASK;

  /* Set the STOPM field to 0b011 for LLS mode  */

  SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;

  SMC_PMCTRL |=  SMC_PMCTRL_STOPM(0x3);

  /*wait for write to complete to SMC before stopping core */

  dummyread = SMC_PMCTRL;

  dummyread++;

  /* Now execute the stop instruction to go into LLS */

  #ifdef CMSIS

  /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */

  SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;

  __wfi();

#else

  stop();

#endif

}

 

 

void llwu_configure(unsigned int pin_en, unsigned char rise_fall, unsigned char module_en ) {

    uint8 temp;

    temp = LLWU_PE2;

    if( pin_en & 0x0080)

    {

        temp |= LLWU_PE2_WUPE7(rise_fall);

        printf("\n LLWU configured pins PTC3/SCI1_RX/FTM0_CH2 is LLWU wakeup source ");

        LLWU_F1 |= LLWU_F1_WUF7_MASK;   // write one to clear the flag

    }

    LLWU_PE2 = temp;

}

 

 

void llwu_isr(void){

   printf("go to LLWU INT");

   if (LLWU_F1 & LLWU_F1_WUF7_MASK) {

   //    printf("****WUF7 was set from PTC3 input  *****\r\n");

       LLWU_F1 |= LLWU_F1_WUF7_MASK;   // write one to clear the flag

       key_weakup=1;

   }

   NVIC_ICPR |= 1 << (LLWU_irq_no%32);

}

 

Here is the outcome:

26.PNG

whenever  I press the button.The mcu will reset,send a 'w' to the uart1 and print the information of llwu init. I don't know why.Could anybody help me?I am really anxious.

Outcomes