- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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
- Labels:
-
ispn:40040:1:0
-
l1:314:1:0
-
PSoC4MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yocchi-san,
thank you very much for your contribution for IFX Community!!
regards