Cannot wake up PSoC 5 after it goes to sleep

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi, hope I can get some help with this issue that has kept me all day trying to figure out what's wrong in my project.

   

I am not able to wake up my device once it goes to sleep.  Attached is a workspace with 2 projects for CY8KIT-050.

   

Project "Test01" is based on AN72382 page 16 to "Change PICU Settings with Firmware".  

   

Project "Test02" is based on AN77900 project "PSoC5_LowPower_Demo".

   

I am able to verify that low power wake up works fine in AN77900 project itself but after copying same code to "Test02", my device still doesn't wake up.  

   

Is there anything else that needs to be set in the project to wake up a PSoC from an input signal ?

   

Following is the code from Test01 where I have 2 input pins: P6[1] and P15[5] (SW2 and SW3 on CY8KIT-050).  Both inputs have resistive pull-ups.

   

int main()
{
    LCD_Start();
    LCD_Position(0,0);
    LCD_PrintString("Low Power Test");
    
    // Set P15[5] to PICU falling-edge trigger
    CY_SET_REG8(CYREG_PICU15_INTTYPE5, 0x02);

   

    // Set P6[1] to PICU falling-edge trigger
    CY_SET_REG8(CYREG_PICU6_INTTYPE1, 0x02);
    
    CyGlobalIntEnable; /* Enable global interrupts. */

   

    // Sleep and wait for PICU interrupt
    // Sleep again if not P6[1] PICU wakeup
    do {
        LCD_Position(1,0);
        LCD_PrintString("Going to sleep");
        // Save clocks and enter sleep
        CyPmSaveClocks();
        CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_PICU);
        
        // Wake up
        CyPmRestoreClocks();
        LCD_Position(1,0);
        LCD_PrintString("Waking up");
        
        // Stay awake for 2 seconds
        CyDelay(2000);
        
    } while (!(CY_GET_REG8(CYREG_PICU6_INTSTAT) & 0x02));
    
    LCD_Position(1,0);
    LCD_PrintString("Exited sleep");
    // Disable P6[1] PICU trigger
    CY_SET_REG8(CYREG_PICU6_INTTYPE1, 0x00);

   

    for(;;)
    {
        /* Place your application code here. */
    }
}

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Attached is an update to the 3 projects with proper solution.

   

Main reason for the issues I was having was a lack of understanding of how GPIOs configured with Interrupts work.  For push buttons I usually connect a debouncer but in this case I couldn't do that because debouncer is dependent on clock and if clock is sleeping, debounce doesn't work.

   

On Test01 I had to add interrupts to SW2 and SW3.  Then in the interrupt function I have to call SWx_ClearInterrupt, otherwise the interrupt function keeps getting called and goes into an infinite loop.  So the reason why none of my codes were waking up is that I wasn't clearing the interrupts.

   

Test02 I enable the interrupt only before going to sleep.  Still this example is not so great because using same button to wake up and sleep has some issues due to lack of debounce code.

   

Test03 was not working because even though I copied everything, I didn't realize that the original project was calling Hibernate_ClearInterrupt and Wakeup_ClearInterrupt from code in the Generated_Source of Hibernate.c and Wakeup.c.

View solution in original post

0 Likes
8 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You did not prepare the LCD for sleep -

   

void LCD_Char_Sleep(void)

   


Description: This is the preferred routine to prepare the component for sleep. The LCD_Char_Sleep()
routine saves the current component state. Then it calls the LCD_Char_Stop() function and
calls LCD_Char_SaveConfig() to save the hardware configuration.
Call the LCD_Char_Sleep() function before calling the CyPmSleep() or the
CyPmHibernate() function. Refer to the PSoC Creator System Reference Guide for more
information about power management functions.

   


Parameters: None

   


Return Value: None

   


Side Effects: Doesn't change component pins’ drive modes. Use Port Component APIs for that purpose.
Because Character LCD is an interface component that has its own protocol, you need to
reinitialize the component after you have saved or restored component pin states.

   

 

   

You would have to use LCD wakeup function and restart it after you wakeup,

   

and restore the pin interface per the notes in the above sleep API.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Hi Dana,

   

I am using the LCD just to troubleshoot.  Problem is that the device is not waking up.  Below is modified code without LCD.  This time I verified that it's not waking up by looking at the clock on the scope.  I can see when clock stops and doesn't run anymore even though I toggle P15[5].

   

int main()
{
    // Set P15[5] to PICU falling-edge trigger
    CY_SET_REG8(CYREG_PICU15_INTTYPE5, 0x02);

   

    // Set P6[1] to PICU falling-edge trigger
    CY_SET_REG8(CYREG_PICU6_INTTYPE1, 0x02);
    
    CyGlobalIntEnable; /* Enable global interrupts. */

   

    // Sleep and wait for PICU interrupt
    // Sleep again if not P6[1] PICU wakeup
    do {
        // Save clocks and enter sleep
        CyPmSaveClocks();
        CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_PICU);
        
        // Wake up
        CyPmRestoreClocks();
        
        // Stay awake for 2 seconds
        CyDelay(2000);
        
    } while (!(CY_GET_REG8(CYREG_PICU6_INTSTAT) & 0x02));
    
    // Disable P6[1] PICU trigger
    CY_SET_REG8(CYREG_PICU6_INTTYPE1, 0x00);

   

    for(;;)
    {
        /* Place your application code here. */
    }
}

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

An ap note on PICU wake up -

   

 

   

http://www.element14.com/community/docs/DOC-62329/l/cypress-ep56137--software-code-example-for-enter...

   

Enter Hibernate Mode and Wakeup Using PICU PSOC 3 / 5LP

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You also need to issue the sleep api for the LCD, and wakeup API when you recover.

   

Note in LCD sleep API there are footnotes on the LCD pin interface you need to

   

take care of when you wakeup.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Dana, 

   

The example you sent me is very good and runs well on its own project; however, when I create a new project using PSoC Creator 3.2 and copy everything, the device just won't wake up.  Looks like an issue with PSoC Creator 3.2 itself.  I have a case open with Cypress and hope to get some feedback on it.

   

If you are curious, attached is my project "Test03" and the project you provided link "Hibernate_WakeupWithPICU".  I run a comparison of directory "Generated_Source\PSoC5" from both projects and the files are nearly identical.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Projects look very similar to each other.

   

I would try

   
        
  • 1st Remove the comment lines containing the #START and #END within your handlers, since they are used for special treatment, maybe they're wrongly interpreted here.
  •     
  • 2nd From TopDesign remove the pins and isrs and manually re-create them. I have seen twice an error that could be cured only by following this.
  •    
   

Happy coding

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Attached is an update to the 3 projects with proper solution.

   

Main reason for the issues I was having was a lack of understanding of how GPIOs configured with Interrupts work.  For push buttons I usually connect a debouncer but in this case I couldn't do that because debouncer is dependent on clock and if clock is sleeping, debounce doesn't work.

   

On Test01 I had to add interrupts to SW2 and SW3.  Then in the interrupt function I have to call SWx_ClearInterrupt, otherwise the interrupt function keeps getting called and goes into an infinite loop.  So the reason why none of my codes were waking up is that I wasn't clearing the interrupts.

   

Test02 I enable the interrupt only before going to sleep.  Still this example is not so great because using same button to wake up and sleep has some issues due to lack of debounce code.

   

Test03 was not working because even though I copied everything, I didn't realize that the original project was calling Hibernate_ClearInterrupt and Wakeup_ClearInterrupt from code in the Generated_Source of Hibernate.c and Wakeup.c.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Very informative post, thanks for taking the time to post back your results.

   

 

   

Regards, Dana.

0 Likes