I2C Master Read Slave device with Sub-Addresses

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

cross mob
Anonymous
Not applicable

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

}

0 Likes
1 Solution
RyanZhao
Moderator
Moderator
Moderator
250 sign-ins First question asked 750 replies posted

Please refer to I2C master examples in PSoC Creator.

Thanks,

Ryan

View solution in original post

0 Likes
2 Replies
RyanZhao
Moderator
Moderator
Moderator
250 sign-ins First question asked 750 replies posted

Please refer to I2C master examples in PSoC Creator.

Thanks,

Ryan

0 Likes
joli_601446
Level 5
Level 5
10 likes given 10 sign-ins 5 sign-ins

Hello, any chance you could upload your design?

Thanks,

Joe

0 Likes