Sleep Mode in LPC1343

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Sleep Mode in LPC1343

5,665 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Fri Aug 19 00:34:57 MST 2011
Hello everyone. I would just like to ask where do the MCU go after a wake up interruption was made during sleep mode. I am using the LPC1343, the flow goes like this, I program a task and if you push the switch in short period three times, it goes to sleep and i set a pin for its wake up. Then after the wake-up my expectation is that is f push the switch again three times in a short period, it would go back to sleep but in my situation it doesn't. So after the wake up, where does the status of my MCU goes. Thanks
0 项奖励
回复
23 回复数

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Tue Aug 23 23:27:44 MST 2011

Quote:

void Wake_Up_Init(void)
{
    /*Turn on the IRC & Flash*/
    LPC_SYSCON->PDRUNCFG |= (0<<0)|(0<<1)|(0<<2);

    /*Swicth MAINCLKSEL to IRC */
    LPC_SYSCON->MAINCLKSEL = 0;
    LPC_SYSCON->MAINCLKUEN = 0;
    LPC_SYSCON->MAINCLKUEN = 1;
    while (!(LPC_SYSCON->MAINCLKUEN & 0x01));

    /*Ensure DPDEN is disabled*/
    LPC_PMU->PCON = (0<<1);

    /*BOD Off, Watchdog Off*/
    LPC_SYSCON->PDSLEEPCFG = 0x00000FFF;

    /*Periherals to be powered up in returning from deep sleep mode*/
    LPC_SYSCON->PDAWAKECFG = LPC_SYSCON->PDRUNCFG;

    /*Wake-up using PIO0_1*/
    LPC_SYSCON->STARTAPRP0        |= (1<<1);
    LPC_SYSCON->STARTRSRP0CLR    |= (1<<1);
    LPC_SYSCON->STARTERP0        |= (1<<1);

    NVIC_ClearPendingIRQ(WAKEUP12_IRQn);
    NVIC_EnableIRQ(WAKEUP12_IRQn);

    /*Specify Deep Sleep Mode*/
    SCB->SCR |= (1<<2);            //Set SLEEPDEEPBIT

    /*Wait for Interrupt, Enter Deep Sleep Mode*/
    __WFI();
}
void Timer(void)
{
    int i;
    for(i=0; i<=500; i++)
    {
        LPC_GPIO1->DATA ^= (1<<10);
    }
    for(i=500; i>=0; i--)
    {
        LPC_GPIO1->DATA ^= (0<<10);
    }
    LPC_IOCON->PIO1_9 &= ~(0x07);
    LPC_IOCON->PIO1_9 |=  (0x00);
    GPIOSetDir(PORT1, 9, 1);
    GPIOSetValue(PORT1, 9, 0);

    LPC_IOCON->R_PIO1_2 &= ~(0x07);
    LPC_IOCON->R_PIO1_2 |=  (0x01);
    GPIOSetDir(PORT1, 2, 1);
    GPIOSetValue(PORT1, 2, 0);
}

thats my code for sleep mode, I only copied it from the sample codes provided by nxp:D..
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Tue Aug 30 19:32:24 MST 2011
hello ktownsend.

As of trying to wake-up usin different switch, I cant do it because now Im not using a development board. I am using the actual board to be use. I started reading the Cortex M user guide and found out that the NVIC cannot be accessed during the non-privileged mode, so is there any way that I could access the NVIC in non privileged mode? Thanks
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Fri Aug 26 08:31:44 MST 2011
If you're not executing your code normally after wakeup there's a problem in your code somewhere.  I'd concentrate on finding that rather than resetting to main, but it's obviously your call.  I'm sure it's a SW issue, but have you tried with seperate HW just to rule that out?  There are only a handful of things it could be, such as the way the wakeup pin is configured, what other interrupt generating code do you have running at the same time as wakeup, etc.?
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Thu Aug 25 22:57:57 MST 2011
hello,

thanks for the code ktownsend, but I already did the same as your code and still I cannot go back to were I stop, so I found a solution to call the NVIC_SystemReset() function in the WAKEUP_IRQHandler, and my MCU goes back to main. My only problem left is that it is now very easy to wakeup my device. So I would like to ask if I could personalize my wake up procedure? Just like if I want to wake up the MCU, I should push the switch for start logic three short switch and one long. thank you very much for the help
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Wed Aug 24 04:24:41 MST 2011
I don't know how useful this is to you since I'm using my own library and header (not CMSIS, etc.), but perhaps you'll spot something you're missing:

https://github.com/microbuilder/LPC1114CodeBase/tree/master/core/pmu

You can call the deep sleep function to either use a timed wakeup or not.  This code works perfectly for me.  It's for the 1114, but the 1343 is identical in every meaningful respect for deep-sleep and waking up.
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Wed Aug 24 01:01:57 MST 2011
hi.

i dont have any idea if where the problem is now. because i only integrated the deep sleep mode in my program, and it is already wide.:confused::eek:..thats why i just copied the code from nxp and modify the pins..hehehe
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Wed Aug 24 00:16:05 MST 2011
Could it be a stack related problem? I noted that the __WFI instruction is in a subroutine.
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Wed Aug 24 00:01:38 MST 2011
hello rob.

yes sir i already did everything. I already did read the user manual and the application notes for low power modes from nxp, in fact I try the code that the nxp provided. but still my programs go nasty after the wake up, I tried to put a program that blinks an LED to the WAKEUP_IRQHandler function and it works, so is it true that after the wake up, the MCU will only execute the code inside the WAKEUP_IRQHandle():confused::confused:..thank you very much
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Aug 23 23:45:53 MST 2011

Quote: straw_hat
but still the last program doesn't continue after the wakeup:(:(:(



There are a number of things that you most likely still missed.
Check the description of PDSLEEPCFG, PDWAKECFG and PDRUNCFG in the user manual. Also check which oscillator you are using. If you are running from the system oscillator with the PLL switched on you will not be able to properly wake up and continue where you left (the PLL is switched of during deep sleep).

I urge you to read the application note that NXP_USA posted and start with the example from that (zip) file. The projects are in LPCXpresso format so that is as easy as importing the project, compile and run.
[B]But do read the PDF document, it contains vital information.[/B]

The application note is really the only viable way to start exploring the different sleep and power down modes. Your application contains too many other things that can go wrong.
Start with the LPC1300_wakeup.zip and add your blinking LED in that application before doing anything else.

Regards,[INDENT]Rob
[/INDENT]
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Tue Aug 23 23:21:56 MST 2011
A pure rethorical question: what happens when a device goes into sleep or deep-sleep mode when servicing a IRQ request?:cool:

And just like Ktownsend said: you should post your code before we can help you out. :D
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Tue Aug 23 17:15:31 MST 2011

Quote: Serge
Just re-activate the clocks in the IRQ handler. After the MCU leaves the IRQ handler he should just continue your program without the need to call anything.
Rob will correct me if i am wrong (i hope :rolleyes: )



ahm...I already did that sir but still the last program doesn't continue after the wakeup:(:(:(
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Tue Aug 23 17:09:17 MST 2011

Quote: KTownsend

What are you putting in the WAKEUP_IRQHandler? You'll really need to post some meaningful code before anyone can help you.


Im put my code in WAKEUP_IRQHandler to blink my LED


Quote: KTownsend

Are you clearing the DEEPSLEEP bit in the system control register, for example (SCB SCR). Are you disabling the timer that you (possibly) used to wake the device up from deep sleep?


Yes sir I clear DEEPSLEEP bit, and disable the timer, anyway I'm not using the self wake-up, I used the external PIN to wake up from deepsleep mode.
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Tue Aug 23 09:28:41 MST 2011

Quote: straw_hat
hello. I already tried but the code is not executed unless it is under the WAKEUP_IRQHandler funcrtion. So is there any other way for me the call the program after it exit at the deep sleep mode???Thanks



You have a problem somewhere in your code, then.

What are you putting in the WAKEUP_IRQHandler?  You'll really need to post some meaningful code before anyone can help you.

Are you clearing the DEEPSLEEP bit in the system control register, for example (SCB SCR).  Are you disabling the timer that you (possibly) used to wake the device up from deep sleep?

It SHOULD continue executing wherever it left off before going into deep sleep (after the ISR mentionned above executes).

Have you tried turning an LED on inside the IRQHandler mentionned above to see if you are waking up?
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Tue Aug 23 03:31:33 MST 2011
Just re-activate the clocks in the IRQ handler. After the MCU leaves the IRQ handler he should just continue your program without the need to call anything.
Rob will correct me if i am wrong (i hope :rolleyes: )
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Tue Aug 23 01:23:22 MST 2011
hello. I already tried but the code is not executed unless it is under the WAKEUP_IRQHandler funcrtion. So is there any other way for me the call the program after it exit at the deep sleep mode???Thanks
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Tue Aug 23 00:24:38 MST 2011

Quote: straw_hat
hello

Thanks for the clarification. So if I did reconfigure manually the clocks etc back to its normal condition, will the MCU resume its previous state before it enters the deep sleep mode??:confused: For example, I blink the LED before it enters the deep power down mode, when I wake it up, the LED will resume blinking??Thank You



The best way to know is to try it :-)

But yes ... after waking up, it will continue executing the code where it left off (after firing the wakeup interrupt).
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Mon Aug 22 17:14:55 MST 2011
hello

Thanks for the clarification. So if I did reconfigure manually the clocks etc back to its normal condition, will the MCU resume its previous state before it enters the deep sleep mode??:confused: For example, I blink the LED before it enters the deep power down mode, when I wake it up, the LED will resume blinking??Thank You
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Mon Aug 22 03:37:14 MST 2011
Unless you have changed the GPIO pin state yourself, both sleep and deep sleep will retain the previous pin config settings.  What you DO need to reconfigure after waking up from deep sleep is the system clocks (as mentionned earlier), such as reconfiguring the PLL, switching back to the external crystal as the clock source instead of the WDT oscilllator, etc.

To get the lowest possible power consumption in deep sleep, however, you may very well need to change the state of the GPIO pins manually before sending the WFI signal and entering deep sleep.  I believe the app note example from NXP sets all the pins to input and GND (off the top of my head, which should give you the lowest power consumption in many situations).  That means that before you go into deep sleep you will need to record the GPIO pin states somwhere in memory, and when you come out of wakeup you will need to set them back to an appropriate state.  I imagine the app not from NXP deals with this, though.
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by straw_hat on Sun Aug 21 20:26:45 MST 2011
hello,

Thanks for the reply. About the application notes from NXP, I already got one. Regarding the self wake up, the part of the code that I dont understand is the config_ios(); Can you please tell me what is the main purpose of that function. My understanding is that it configures the IOS after the wake up, so after the wake up will that code reconfigures my previous configuration of the GPIO. Please help me out because my knowledge is too narrow. Thanks
0 项奖励
回复

5,336 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Fri Aug 19 15:00:10 MST 2011
Hi,

There is also LPC13xx app note/software example you can look at:
http://ics.nxp.com/support/documents/microcontrollers/zip/an10973.zip

It talks about the wake-up implementation for each mode and wake-up times.
Software example should show what initialization steps are needed.

Thanks.
0 项奖励
回复