PSOC5LP i2c read buffer issue

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.
alro_2373731
Level 1
Level 1

Update 8:47 PM: after looking at it with a logic analyzer, it appears the first byte of the read buffer is firing off immediately...  is there no way to control the delay on the read buffer being exposed so quickly? Im running i2c at 100khz and I find it odd that I cant get in front of the byte.

Screen Shot 2018-02-13 at 8.45.43 PM.png
Note, the CyDelay(1000)(line: 25) occurs after 0xFF in the above capture, I don't think its possible to disable the interrupts fast enough.

Original Post:

I am using the psoc5lp as a slave and when exposing the read buffer for the master, it always uses the previous value of the last transaction in index #0.  I see there are other users having the same issue.  I am in belief now there is is a flaw with read buffer or something is not documented correctly with the i2c component. I have attached the project to this post.  I have attached an image of the bridge control showing the output, It first writes a command to slave 60 and reads back at 61.  The first byte shows 0xFF while it should be 0x0A.  The delay of 1 second demonstrates that there is no timing issue with the first byte being read faster than the succeeding bytes.

Reference link to another user have time same issue. PSoCDeveloper • Incorrect first byte of data during I2C Reads

Screen Shot 2018-02-13 at 4.49.41 PM.png

#include <project.h>

#include <stdio.h>

#define I2CBUFFERSIZE 10

uint8 i2cReadBuffer[I2CBUFFERSIZE];

uint8 i2cWriteBuffer[I2CBUFFERSIZE];

int main()

{

    CyGlobalIntEnable; /* Enable global interrupts. */

 

    /* Start I2C slave (SCB mode) */

    I2C_1_Start();

    I2C_1_SlaveInitReadBuf(i2cReadBuffer,  I2CBUFFERSIZE);

    I2C_1_SlaveInitWriteBuf(i2cWriteBuffer, I2CBUFFERSIZE);

    for(;;)

    {

        CyWdtClear();

    

        /* Write complete: parse command packet */

        if (0u != (I2C_1_SlaveStatus() & I2C_1_SSTAT_WR_CMPLT))

        {  

           CyGlobalIntDisable;

           CyDelay(1000);

           for(int i = 0; i < I2CBUFFERSIZE; i++){

              i2cReadBuffer = i+10; // Expected output should be 0x0A, 0x0B, 0x0C.....

           }

           CyGlobalIntEnable;

       

       

           /* Clear slave write buffer and status */

           I2C_1_SlaveClearWriteBuf();

           (void) I2C_1_SlaveClearWriteStatus();

        }

        /* Read complete: expose buffer to master */

        if (0u != (I2C_1_SlaveStatus() & I2C_1_SSTAT_RD_CMPLT))

        {

            /* Clear slave read buffer and status */

            I2C_1_SlaveClearReadBuf();

            (void) I2C_1_SlaveClearReadStatus();

            for(int i = 0; i < I2CBUFFERSIZE; i++){

                i2cReadBuffer = 0xFF;

            }

           

        }

    }

}

/* [] END OF FILE */

0 Likes
0 Replies