How to implement PSOC 101: Lesson 16 and Lesson17

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

cross mob
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hello,

In PSoC 101: Lesson 16,  the CySysPmSleep() API doesn't take any arguments whereas when I am trying with PSOC Creator 4.4, there is no CySysPmSleep() API, but instead a CyPmSleep() API which requires two arguments (Wakeup Time, Wakeup source). 
I have gone through the inbuilt Sleep_Timer_Wakeup example which makes use of a special Sleep_Timer component (I think)... and also tried using the CyPmSaveClocks() and CyPmRestoreClocks() API's before and after calling the CyPmSleep() API --> The device goes to sleep, but doesn't wakeup.

Can anyone help understand how to bring the same functionality of Lesson 16, using a user-defined timer to the sleep project?

Similarly in Lesson 17, the deep sleep mode is achieved using the CySysPmDeepSleep() API (which is not available), and so i tried using CyPmHibernate() (similar to the PowerManagement_Hibernate example firmware), but when trying to write to the i2cbuf from the Bridge Control Panel application, the Slave is NACKing the commands --> Failure.


Please help on how to implement these examples with CY8CKIT-059 and PSoC Creator 4.4.

Regards,
Yash

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Although it's not exactly the 101 is showing, I found a sample which I wrote last year.

I hope this can be some hint for you.

Schematic

001-schematic.JPG

Pins

002-Pins.JPG

Tera Term logs

1. When program started

Start up message is printed and the on board LED is blinking

003-started.JPG

2. When sw1 is pushed

The program goes into CyPmHibernate() and the LED turned off

004-sw_pushed.JPG

3. When sw1 is pushed again

Program reports that it wok up. And the LED starts blinking again.

005-sw_pushed_again.JPG

#include "project.h"
#include "stdio.h"

#define LED_ON 1u
#define LED_OFF 0u

#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str) ;
void cls(void) ;
void splash(char *prog_name) ;
void init_hardware(void) ;

volatile int sw_flag = 0 ;

CY_ISR(sw1_isr)
{
    SW1_ClearInterrupt() ;
    sw_flag = 1 ;
}

int main(void)
{
    init_hardware() ;
    
    splash("5LP Repeated LowPower Test") ;

    LED_Write(LED_ON) ;
    
    for(;;)
    {
        if (sw_flag) {
            print("Entering Low Power Mode ... ") ;
            CyDelay(10) ;
            CyDelayUs(20);
            CyPmSaveClocks();
            LED_Write(LED_OFF) ;
            CyPmHibernate();
            CyPmRestoreClocks(); // <= Stack in this process
            CyDelayUs(20);
            print("Woke Up!\n\r") ;
            sw_flag = 0 ;
        }
        LED_Write(!LED_Read()) ;
        CyDelay(500) ;
    }
}

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    
    LED_Write(LED_OFF) ;
    
    UART_Start() ;
    
    SW1_ClearInterrupt() ;
    isr_1_ClearPending() ;
    isr_1_StartEx(sw1_isr) ;
}

void print(char *str)
{
    UART_PutString(str) ;
}

void cls(void)
{
    print("\033c") ; /* reset */
    CyDelay(20) ;
    print("\033[2J") ; /* clear screen */
    CyDelay(20) ;
}

void splash(char *prog_name) 
{
    cls() ;
    if (prog_name && *prog_name) {
        print(prog_name) ;
    } 
    print(" (") ;
    print(__DATE__) ;
    print(" ") ;
    print(__TIME__) ;
    print(")\n") ;
}

 

moto

View solution in original post

0 Likes
9 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Although it's not exactly the 101 is showing, I found a sample which I wrote last year.

I hope this can be some hint for you.

Schematic

001-schematic.JPG

Pins

002-Pins.JPG

Tera Term logs

1. When program started

Start up message is printed and the on board LED is blinking

003-started.JPG

2. When sw1 is pushed

The program goes into CyPmHibernate() and the LED turned off

004-sw_pushed.JPG

3. When sw1 is pushed again

Program reports that it wok up. And the LED starts blinking again.

005-sw_pushed_again.JPG

#include "project.h"
#include "stdio.h"

#define LED_ON 1u
#define LED_OFF 0u

#define STR_LEN 64
char str[STR_LEN+1] ;
void print(char *str) ;
void cls(void) ;
void splash(char *prog_name) ;
void init_hardware(void) ;

volatile int sw_flag = 0 ;

CY_ISR(sw1_isr)
{
    SW1_ClearInterrupt() ;
    sw_flag = 1 ;
}

int main(void)
{
    init_hardware() ;
    
    splash("5LP Repeated LowPower Test") ;

    LED_Write(LED_ON) ;
    
    for(;;)
    {
        if (sw_flag) {
            print("Entering Low Power Mode ... ") ;
            CyDelay(10) ;
            CyDelayUs(20);
            CyPmSaveClocks();
            LED_Write(LED_OFF) ;
            CyPmHibernate();
            CyPmRestoreClocks(); // <= Stack in this process
            CyDelayUs(20);
            print("Woke Up!\n\r") ;
            sw_flag = 0 ;
        }
        LED_Write(!LED_Read()) ;
        CyDelay(500) ;
    }
}

void init_hardware(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    
    LED_Write(LED_OFF) ;
    
    UART_Start() ;
    
    SW1_ClearInterrupt() ;
    isr_1_ClearPending() ;
    isr_1_StartEx(sw1_isr) ;
}

void print(char *str)
{
    UART_PutString(str) ;
}

void cls(void)
{
    print("\033c") ; /* reset */
    CyDelay(20) ;
    print("\033[2J") ; /* clear screen */
    CyDelay(20) ;
}

void splash(char *prog_name) 
{
    cls() ;
    if (prog_name && *prog_name) {
        print(prog_name) ;
    } 
    print(" (") ;
    print(__DATE__) ;
    print(" ") ;
    print(__TIME__) ;
    print(")\n") ;
}

 

moto

0 Likes

EDITED!!!

Hello Tanaka-san,

Thank you for sharing the project. Works great!!!

 

I was wondering on how we can use CyPmSleep() API and implement the normal sleep functionality. 
Can you please help with this?

Also, from the program shared above, what would need to be changed in order to use the EZI2C (Similar to Lesson 17) instead of the switch?
-- I understand that the Deep Sleep function is not supported by PSOC 5LP (System Reference Guide, Pg. 49, Table.1).

Regards,
Yash

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I have just posted a sample for Lesson 16.

https://community.cypress.com/t5/Code-Examples/PSoC-5LP-sample-for-PSOC101-Lessong-16-counter-part/m...

I'm going to work on Lesson 17, but I don't know when it's going to be available...

moto

0 Likes

Hello Tanaka-san,

I downloaded the project attached with the code example and tried to run it.
The device goes to sleep, but there's no wake up text on UART even after waiting for a minute.
The UART log:

Yash_r_0-1627625688341.png


Can you think of what can be the issue causing this?

Regards,
Yash

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

It was my bad, seeing the table, I realized that we can not wake up using timer interrupt.

So I deleted my code example thread.

We may be able to use CTW, which I have been trying, but not successful yet.

I will add reply if I will be able to find a method.

But for the time being please survive with the lesson 17 example 😉

moto

lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi, 

From the PSoC Creator's Code Example, I found

"SleepTimer_Interrupt_Sleep", which is using CTW.

And I modified it to use CY8CKIT-059.

moto

 

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

For the lesson 17, as you found, we don't have "Deep Sleep" and we can not wake up from Hibernate using I2C as the table below suggests.

024-table16.JPG

So I modified the lesson 17 to use "CyPmSleep()" 

1. Schematic

020-schematic.JPG

2. I2C (EZI2C) Config

Note: I2C1 is needed to be used!

021-EZI2C_Config.JPG

3. Pins

022-Pins.JPG

main.c

#include "project.h"
#include "stdio.h"

#define LED_ON 1u
#define LED_OFF 0u

void blink_led(int num)
{
    int i ;
    for (i = 0 ; i < num ; i++ ) {
        LED_Write(LED_ON) ;
        CyDelay(100) ;
        LED_Write(LED_OFF) ;
        CyDelay(100) ;
    }
}

int main(void)
{
    uint8_t i2cbuf[1] ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */  
    
    EZI2C_Start() ;
    EZI2C_SetBuffer1(1, 1, i2cbuf) ;
            
    for(;;)
    {
        blink_led(4) ;
        
        EZI2C_Sleep() ;
        CyPmSaveClocks();
//        CyPmHibernate();
        CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_I2C) ;
        CyPmRestoreClocks(); // <= Stack in this process
        EZI2C_Wakeup() ;        

        CyDelay( 5000 ) ;
    }
}

 

Can we call it a week?

moto

0 Likes

Tanaka-san,

Thanks for all your help!!!🙌
You really are a life-saver and very knowledgeable.

I just had a small doubt as to why we can't use I2C0 and only need to use I2C1 for Lesson17?

Regards,
Yash

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

In the TRM, there is the following table.

According to the table, P12[0:1] are for I2C1 (as their dedicated I/Os).

Although I2C0 may be able to use these pins, the signals need to go through

other internal switch(es) and they may not be working when the device is in low power mode.

040-Table_26_2.JPG

moto

0 Likes