How to add a sleep function and wait for interrupt to wake?

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

How to add a sleep function and wait for interrupt to wake?

1,784 Views
albert_zhou
Contributor III

I try to add a sleep function to reduce the MKL27Z644 power current. Code as below:

void sleep(void);

main()

{

initial();

SMC->PMPRORT =-1;      //added for sleep mode

while(1)

{

 processing();

sleep();                      //enter sleep for LPUART interrupt to wake up into rum mode.

}

}

void sleep(void)

{

 SCB->SCR &=~SCB_SCR_SLEEPDEEP_MASK;

SMC->PMCTRL = BIT6;   //RUNM VLPR;

_enable_irq();

//asm("WFI");

_ISB();

}

 It is not work at all. I don't know how to make this to work. I could not add the line 'asm("WFI") that disables LPUART interrupt.

Labels (1)
0 Kudos
2 Replies

1,597 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello Albert Zhou

I suggest you to refer to the sdk examples to implement sleep function Welcome | MCUXpresso SDK Builder.

To add the WFI line please refer to this definition on the sdk example:

pastedImage_3.png

 

For more detailed information about power management, please refer to this application note: https://www.nxp.com/docs/en/application-note/AN4503.pdf

Also note that in order to enter into a power mode is important to implement a wakeup routine.

 

Let me know if this is helpful. If you have more specific questions do not hesitate to ask me.

Best regards,

Omar

0 Kudos

1,597 Views
albert_zhou
Contributor III

Hi Omar,

Thanks for your response and help. I see the line __WFI() defines.

I have to stay in Kinetis SDK because it is complicated when you move all the projects with a bootloader from Kinetis to MCUXpressor.

The original project already has interrupt LPUART1, I just need to put the chip into sleep and it wakes up by the Modbus LPUART1.

I follow the AN4503 tried sleep function and VLPR and VLPS functions. All of them won’t work, except the VLPS mode does put it into deep sleep but could not wake up. It seems the line asm(“WFI”) disabled LPUART1 even at sleep().

Best regards,

Albert Zhou

Sr. Electronics Engineer

Sensorex

p:

+1 714 230 2768

a:

11751 Markon Drive, Garden Grove, CA 92841

w:

e:

www.sensorex.com<http://t.sidekickopen05.com/s1t/c/5/f18dQhb0S7lM8dDMPbW2n0x6l2B9nMJN7t5X-Ff4Yc8W4WJ...;

albert.zhou@sensorex.com<mailto:albert.zhou@sensorex.com>

<https://www.facebook.com/Sensorex> <http://t.sidekickopen05.com/s1t/c/5/f18dQhb0S7lM8dDMPbW2n0x6l2B9nMJN7t5X-Ff4Yc8W4WJpMP7dWWcgW6ND00211fj5b0?t=https%3A%2F%2Ftwitter.com%2FSensorexInc&si=7000000000014733&pi=ca5a45ef-58ca-4f28-9010-24a9c3d147a2> <http://t.sidekickopen05.com/s1t/c/5/f18dQhb0S7lM8dDMPbW2n0x6l2B9nMJN7t5X-Ff4Yc8W4WJpMP7dWWcgW6ND00211fj5b0?t=https%3A%2F%2Fwww.linkedin.com%2Fcompany-beta%2F1768298%2F&si=7000000000014733&pi=ca5a45ef-58ca-4f28-9010-24a9c3d147a2>

0 Kudos