Wake up from DeepSleep mode with I2C slave communication for CY8CKIT-145-40XX

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

cross mob
YoIs_1298666
Level 5
Level 5
250 sign-ins 100 replies posted 100 sign-ins

Hello,

This is a sample code for wakeup from DeepSleep using I2C slave communication for CY8CKIT-145-40XX.

In case of polling contrtol, the following code will be written as the main function.

************************************************************************************************************

for(;;)
{

/* Write buffer(master -> slave) */

if (0u != (I2CS_I2CSlaveStatus() & I2CS_I2C_SSTAT_WR_CMPLT))      ....... Conditional statement (1)
{

      Processing the data, Clearing the buffer and status

}

/* Read buffer(master <- slave) */

if (0u != (I2CS_I2CSlaveStatus() & I2CS_I2C_SSTAT_RD_CMPLT))     ....... Conditional statement (2)
{

      Clearing the buffer and status

}

/* Low power modes */

/* Enter critical section to lock the slave state */
      uint8 intState = CyEnterCriticalSection();
      /* Check if slave is busy */
      status = (SCB_I2CSlaveStatus() & (SCB_I2C_SSTAT_RD_BUSY | SCB_I2C_SSTAT_WR_BUSY));
      if (0u == status)                                                                                                ....... Conditional statement (3)
      {
            /* Slave is not busy: enter Deep Sleep */
            SCB_Sleep(); /* Configure the slave to be wakeup source */
            CySysPmDeepSleep();

            /* Exit critical section to continue slave operation */
            CyExitCriticalSection(intState);
            SCB_Wakeup(); /* Configure the slave to active mode operation */
      }
      else
      {
            /* Slave is busy. Do not enter Deep Sleep. */
            /* Exit critical section to continue slave operation */
            CyExitCriticalSection(intState);
      }
}

************************************************************************************************************

Conditional statement(3) may be processed before processing either conditional statement(1) or (2).

The read data for wakeup may be corrupted.

YoIs_1298666_1-1654575453023.png

Then, the "if" statement of Conditional statement (3) is as follows.

************************************************************************************************************

status = (I2CS_I2CSlaveStatus() & (I2CS_I2C_SSTAT_RD_BUSY | I2CS_I2C_SSTAT_WR_BUSY));
if (0u == status && i2cs_deepsleep_flag == CLEAR)
{
}
************************************************************************************************************

The i2cs_deepsleep_flag is set in the void I2CS_I2C_SlaveCompleteCallback (void) API.

************************************************************************************************************

void I2CS_I2C_SlaveCompleteCallback(void)
{
      if (0u != (I2CS_I2CSlaveStatus() & I2CS_I2C_SSTAT_WR_CMPLT) ||
      0u != (I2CS_I2CSlaveStatus() & I2CS_I2C_SSTAT_RD_CMPLT))
      {
            i2cs_deepsleep_flag = SET;
      }
}

************************************************************************************************************

As a result, data can be reliably written and read in I2C slave communication for wakeup.

Comment out "#define FLAG_CONTROL" in main.c to disable i2cs_deepsleep_flag.

************************************************************************************************************

/* I2C slave flag control for low power mode in case of WR & RD completion polling */
//#define FLAG_CONTROL

************************************************************************************************************

Best regards,

Yocchi

 

0 Likes
1 Reply
Takashi_M
Moderator
Moderator
Moderator
1000 replies posted 500 solutions authored 750 replies posted

Yocchi-san,

thank you very much for your contribution for IFX Community!!

 

regards

0 Likes