I2C Master read specific byte from slave

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

cross mob
fawa_2830251
Level 1
Level 1

Hello everyone,

Recently, I need to use I2C master component to read specific byte from slave with PSoC5LP development kit, but the mechanism in the I2C master sample code shows how to read whole buffer from slave.

What I want is to when I key in 0x07 to PSoC, then the I2C master component will only read the value of 7th byte from slave without reading Byte0-6. Is there any hint/direction/sample code for me to implement the function?

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When your PSoC5 is the master then you need to act differently:

When you want to read from a device you use (example for reading two bytes

    I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing

    I2C_MasterWrite(Register);                // Indicate which register you want to write to

    I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);

    I2C_MasterReadByte(I2C_ACK_DATA);            // Read first byte from register

    I2C_MasterReadByte(I2C_NAK_DATA);            // Read second byte from register, last byte is NAKed

    I2C_MasterSendStop();                    // End of transaction

Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

Bob

View solution in original post

2 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When your PSoC5 is the master then you need to act differently:

When you want to read from a device you use (example for reading two bytes

    I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing

    I2C_MasterWrite(Register);                // Indicate which register you want to write to

    I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);

    I2C_MasterReadByte(I2C_ACK_DATA);            // Read first byte from register

    I2C_MasterReadByte(I2C_NAK_DATA);            // Read second byte from register, last byte is NAKed

    I2C_MasterSendStop();                    // End of transaction

Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

Bob

Hi Bob,

Thanks for response, I've successfully implement the function in the demo board.

0 Likes