cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

joli_601446
Contributor

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
BragadeeshV
Moderator
Moderator

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
BragadeeshV
Moderator
Moderator

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
joli_601446
Contributor

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