You are here

Sleep mode not working as expected | Cypress Semiconductor

Sleep mode not working as expected

Summary: 22 Replies, Latest post by U2 on 29 Jan 2012 11:34 PM PST
Verified Answers: 0
Last post
Log in to post new comments.
Rocketmagnet's picture
User
159 posts

Hi,

I am trying to use sleep mode, but I'm experiencing two problems:

1. Only the first sleep seems to work. Subsequent sleep commands seem to pass instantly.

2. Even that first working sleep seems to be the wrong length of time.

 

Here is my code:

 

void main()
{
    UART_Debug_Start();
   
    UART_Debug_PutString("\r\nHello\r\n");
    CyDelay(2000);

    while(1)
    {
        UART_Debug_PutString("going to sleep ...\r\n");
        while(UART_Debug_GetTxBufferSize())                  // Wait for the UART to finish
        {
        }
        CyDelay(5);                                          // Still needs more time
       
        UART_Debug_Sleep();
       
        CyPmSaveClocks();
        CyPmSleep(PM_SLEEP_TIME_CTW_4096MS, PM_SLEEP_SRC_NONE);
        CyPmReadStatus();
        CyPmRestoreClocks();

        UART_Debug_Wakeup();

        CyDelay(5);                                          // Needed otherwise UART doesn't work.
        UART_Debug_PutString("...woken up\r\n");
        CyDelay(4096);
    }
}

 

What have I forgotten?

Many thanks - Hugo

 

U2
uday's picture
Cypress Employee
569 posts

Is the project built for PSoC3 or PSoC5 ?

Rocketmagnet's picture
User
159 posts

PSoC 3. Sorry, forgot to mention that.

dasg's picture
Cypress Employee
730 posts

Hi Rocketmagnet,

 

I haven't tried the code which you have put up yet. But the length of the Sleep time may not be exactly 4096ms as the Internal 1kHz Oscillator has a comparitively larger tolerance than the internal IMO.

Rocketmagnet's picture
User
159 posts

 It's not that the sleep time isn't exactly 4096ms, it that the sleep time is closer to 50ms. I.E. it's waking up immediately from sleep.

user_1377889's picture
User
10803 posts

Hi,

it comes to my mind, that your questioning about a complete transfer of data my not be correct, you just ask, if the allocated buffer has been transfered to the UART-Fifo. This seemingly is the reason for some of your delays you inserted and commented them as neccessary.

I would (but didn't try) to use the UART_ReadTxStatus() function and mask out the values for FiFo empty and Tx complete to be sure that the UART has finished all characters.

I don't think that this is the source of your sleep-malfunction, but so you can get rid of all your CyDelays.

Happy coding

Bob

Rocketmagnet's picture
User
159 posts

Thanks Bob, I'll try that.

 

Does anyone have any thoughts on the sleep problem?

user_1377889's picture
User
10803 posts

Well, in the back of my mind I have the idea that an interrupt is disturbing the "going to sleep". What happens, when you just toggle a LED when sleeping (switch off, before and switch on when awaken) and comment-out all the UART-stuff. When that doesn't work there's something wrong with your CyPmSleep parameters. Else something is horrorbly bad with your UART.

Bob

 

U2
uday's picture
Cypress Employee
569 posts

The thing that I observe here is, the API call CyPmReadStatus()does not seem to have any parameters. Can you try this,

CyPmReadStatus(CY_PM_CTW_INT);

user_1377889's picture
User
10803 posts

Where is your global interrupt enable     CYGlobalIntEnable ?

Bob

 

Rocketmagnet's picture
User
159 posts

 > CyPmReadStatus(CY_PM_CTW_INT);

 

Thanks, I'll try this tonight.

 

Log in to post new comments.