Help with High-level I2C MasterReadBuff

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.
joli_601446
Level 5
Level 5
10 likes given 10 sign-ins 5 sign-ins

Hello, I'm stuck in trying to get a simple example working that include an I2C Master and I2C Slave. I trying to use the high-level API's to do a MasterReadBuff function call.

void InitializeSystem(void)   //    Start all components, initialize  variables, perform self-test

{

uint8 ii;

    CyGlobalIntEnable;

    for(ii = 0; ii < BUFFSIZE; ii++)

    {

   SlaveSendBuffer[ii] = ii;

    }

   

    PWM_Start();

    Slave_I2C_SlaveInitReadBuf(SlaveSendBuffer, BUFFSIZE);

    Slave_I2C_SlaveInitWriteBuf(SlaveReceiveBuffer,BUFFSIZE);

Slave_I2C_Start();   //    Initialize I2C slave

   

    Master_I2C_Start();

   

PWM_WriteCompare(1);

}

int main()

{

int i,k;
uint32 MStatus;
uint8 temp =0;
uint8 mydata = 1;
uint8 write_data_buffer[SUB_ADDR_LENGTH] = {SUB_ADDR_LOCATION};

   

    InitializeSystem();

MStatus = Master_I2C_MasterSendStart(SlaveAddr,Master_I2C_WRITE_XFER_MODE);// Initialize a transaction for writing 
    
Master_I2C_MasterClearStatus();
      
Master_I2C_MasterReadBuf(SlaveAddr,  Master_Rd_Buffer,   READ_DATA_LENGTH, Master_I2C_MODE_REPEAT_START);
      
while(0u == (Master_I2C_MSTAT_ERR_XFER & Master_I2C_MSTAT_RD_CMPLT))
      
temp++;

  

}

I'm having trouble reading from the SlaveReceive Buffer. Can anyone give me some help?

Thanks,

Joe

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi Joe,

1. I2C_MasterReadBuf() will generate a start condition, slave address and the read/ write bit and will byte after byte in the further transactions. All these are managed by the ISR. Hence the I2C_MasterSendStart() is not required.

2. The right condition to wait for the transaction to get completed is:

while(0u == (Master_I2C_MasterStatus() & (Master_I2C_MSTAT_ERR_XFER  |  Master_I2C_MSTAT_RD_CMPLT)))    

{

}

I have attached the modified project with this response. Hope it helps!

Regards,

Bragadeesh

Regards,
Bragadeesh

View solution in original post

0 Likes
2 Replies
lock attach
Attachments are accessible only for community members.
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi Joe,

1. I2C_MasterReadBuf() will generate a start condition, slave address and the read/ write bit and will byte after byte in the further transactions. All these are managed by the ISR. Hence the I2C_MasterSendStart() is not required.

2. The right condition to wait for the transaction to get completed is:

while(0u == (Master_I2C_MasterStatus() & (Master_I2C_MSTAT_ERR_XFER  |  Master_I2C_MSTAT_RD_CMPLT)))    

{

}

I have attached the modified project with this response. Hope it helps!

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes
lock attach
Attachments are accessible only for community members.

Bragaheesh,

Hello, and thank you for solving my problem. All working now! I also have to say thanks for Bob, he has helped me a lot.

Have a great day!

Joe

0 Likes