Announcements

Equip yourself to optimize PSoc4 MCUs for Evs at the EV Webinar. Click here to register.

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

PSoC™ 4 Forum Discussions

sapc_3956266
Level 2
Level 2

We are using PSOC4 I2C in slave mode. The master writes to slave based on events.

Currently we are waiting for master to respond. We are polling the flag as below :

The timeout is creating trouble as PSOC is very busy & need to handle other task. So, We need to trigger interrupt after master completes write operation in slave buffer.

We have found reference for macro call backs as shared below. But in Macro callbacks there is no callbacks to check write_complete.

There should be some macro-callback function for replacing this flag I2CS_I2C_SSTAT_WR_CMPLT .

is there any link missing ?

what is the proper way to do this ?

References :

I2C_SSTAT_WR_CMPLT & Macro Callbacks : https://www.cypress.com/file/175671/download

Macro callback thread from community: https://community.cypress.com/message/152518#152518

I2C BLOCK DATATSHEET : https://www.cypress.com/file/130966/download

Example: https://www.cypress.com/documentation/code-examples/ce224599-psoc-4-i2c-slave-serial-communication-b...

cystatus I2CProtocol_CommRead(uint8 pData[], uint16 size, uint16 * count, uint8 timeOut)

{

    cystatus status;

    uint32 timeoutMs;

    status = CYRET_BAD_PARAM;

    if ((NULL != pData) && (size > 0u))

    {

        status = CYRET_TIMEOUT;

      timeoutMs = ((uint32) 10u * timeOut); /* Convert from 10mS check to 1mS checks */

        while (0u != timeoutMs)

        {

            /* Check if host complete write */

            if (0u != (I2CS_I2C_SSTAT_WR_CMPLT & I2CS_slStatus))  // <------------------------------check this---------

            {

                /* Copy number of written bytes */

                *count = (uint16) I2CS_slWrBufIndex;

                /* Clear slave status and write index */

                I2CS_slStatus = 0u;

                I2CS_slWrBufIndex = 0u;

                /* Copy command into bootloader buffer */

                (void) memcpy((void *) pData, (const void *) I2CS_slWriteBuf,

                                              I2CS_BYTES_TO_COPY(*count, size));

                status = CYRET_SUCCESS;

                break;

            }

            CyDelay(I2CS_WAIT_1_MS);

            --timeoutMs;

        }

    }

    return(status);

}

0 Likes
1 Solution

Hi,

There are no code egs as such. However, I have modified an existing code example to showcase the usage of interrupt handlers.

You can refer to the attached project. I have created an interrupt to be triggered when a stop condition is detected on the bus.

You can use Bridge control panel to emulate as I2C master and use the .iic file in the project.

Thanks,
Shanmathi

View solution in original post

0 Likes
5 Replies
ShanmathiN_06
Employee
Employee
25 likes received 10 likes received First like received

Hi,

Can you pls let us know if you are using a SCB-based I2C slave?

If yes, you can refer to the Section Macro callbacks and Interrupt APIs of component datasheet: https://www.cypress.com/file/408071/download

Maybe, you could set the Rx FIFO level and use SCB_SetRxInterruptMode() to generate an interrupt when the number of data elements is greater than the FIFO level. Else, you could wait for a stop condition on the bus by using SCB_GetSlaveInterruptSource() and trigger an interrupt by using SCB_SetSlaveInterruptMode.

Thanks,
Shanmathi

0 Likes

Yes, using SCB based I2C.

I think SCB_INTR_SLAVE_I2C_WRITE_STOP, will work for us.

interrupt-mode

SCB_SetSlaveInterruptMode(SCB_INTR_SLAVE_I2C_WRITE_STOP);

int inrpt_mask=0;

inrpt_mask = SCB_GetSlaveInterruptMode();

if(inrpt_mask & SCB_INTR_SLAVE_I2C_WRITE_STOP)

{

//application code

}

macro-callback

//Enable or create below in cyapicallbacks.h

#define SCB_I2C_SLAVE_CMPLT_CALLBACK

SCB_I2C_SlaveCompleteCallback(void);

// Define  SCB_I2C_SlaveCompleteCallback(); in any .c file

//in this we just need to enable one flag of pending request

are above methods correct  or any suggestions ?

is there any example code for this application ?

0 Likes

Hi,

There are no code egs as such. However, I have modified an existing code example to showcase the usage of interrupt handlers.

You can refer to the attached project. I have created an interrupt to be triggered when a stop condition is detected on the bus.

You can use Bridge control panel to emulate as I2C master and use the .iic file in the project.

Thanks,
Shanmathi

0 Likes

Hi,

Are there any updates? Did the project work?

Thanks,
Shanmathi

0 Likes

Hi Shanmathi,
Sorry for the late response. I tested your code, it works fine.

Now, I am implementing the same in my architecture.
I will check that and get back to you.

0 Likes