1 Reply Latest reply on Jan 30, 2018 1:07 AM by rzzh

    I2C Master Read Slave device with Sub-Addresses

    lalit.bhambhani_1665456

      Hello,

       

      I'm using PSoC 5LP I2C Master device. I have to read and write from a slave device which has sub-addresses. I'm able to write to the device, now I want to read back what I wrote to verify that the writes are done.  My example code for write is given below. How would I do something similar for read.

       

      Thanks.

       

      uint8 temp = 0;

      i2c_slv_addrs = slave_address >> 1;      // I2C slave address, shift right by 1 bit, 7 bits addressing

      slave_sub_reg[0]      = sub_address;       // sub address

      slave_sub_reg[1]      = data_to_write;      // data to write

            

      do

      {

      temp = I2C_MasterWriteBuf(i2c_slv_addrs, (uint8 *)slave_sub_reg, 2 , I2C_MODE_COMPLETE_XFER);

      }

      while (temp != I2C_MSTR_NO_ERROR);

            

      // stay here until full xfer is done

      while(I2C_MasterStatus() & I2C_MSTAT_XFER_INP);

            

      temp = HDMI_I2C_MasterClearStatus();

            

      // If there is an error while transferring data

      if(temp & HDMI_I2C_MSTAT_ERR_XFER)

      {

      // Indicate the error

      }