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

PSoC™ 5, 3 & 1 Forum Discussions

YuSh_1679151
Level 1
Level 1
First like received

Hello,

Please tell me how to implement a simple I2C slave application.

I want to make a I2C slave application using PSoC 5LP.

Attaching project is a simple I2C slave project file.

Connecting PSoC with I2C Master with two pullup registers, I monitored signal line by the oscilloscope.

No signal was founded and slave status was always 0.

The I2C master was working when I connected another I2C slave module.

Thank you.

0 Likes
1 Solution

The slave cannot send data to the master, only the master can read from the slave.

Byte I2C interface is quite simple: After setting up the component and starting it you use

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

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

    I2C_MasterWriteByte(Value);                // Write to register

    I2C_MasterSendStop();                    // End of transaction

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 from register

    I2C_MasterReadByte(I2C_NAK_DATA);            // Read 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.

The high-level APIs must be used in this way:

Writing to slave Count bytes

I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER);

Reading from Slave sending register/command byte first:

I2C_MasterWriteBuf(SlaveAddress,&RegAddress,1,I2C_MODE_NO_STOP);

I2C_MasterReadBuf(SlaveAddress,DataPtr,Count,I2C_MODE_REPEAT_START);

Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When you are using a CY8CKIT-059: Pin p0_3 has a bypass cap that will not work as I2C terminal.

Bob

Dear Bob,

Thank you for your comment.

I could get the data from I2C Master when I changed the I2C pin.

The slave can get the data from the master, but can't send the data to the master.

The maste don't get correct data.

Could you give an advice about data sending to the maseter?

Thank you,

Yuya

0 Likes

The slave cannot send data to the master, only the master can read from the slave.

Byte I2C interface is quite simple: After setting up the component and starting it you use

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

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

    I2C_MasterWriteByte(Value);                // Write to register

    I2C_MasterSendStop();                    // End of transaction

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 from register

    I2C_MasterReadByte(I2C_NAK_DATA);            // Read 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.

The high-level APIs must be used in this way:

Writing to slave Count bytes

I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER);

Reading from Slave sending register/command byte first:

I2C_MasterWriteBuf(SlaveAddress,&RegAddress,1,I2C_MODE_NO_STOP);

I2C_MasterReadBuf(SlaveAddress,DataPtr,Count,I2C_MODE_REPEAT_START);

Bob

0 Likes