cancel
Showing results for 
Search instead for 
Did you mean: 

PSoc as I2C Master and ST as I2C Slave

HHOKE.1
Associate

Hi,

I want to implement I2C communication between PSOC and ST.

I've configured PSoc as I2C Master and ST as I2C Slave. I've succesfully transferred data from PSoc to ST but I'couldn't read data from ST.

Here's the details about my implemention.

When I use I2C_Write_Data function on PSoc side, I didn't encounter a problem about the data transmission to ST from PSoC

I'didnt implement I2C Slave on ST side before. I may have used wrong APIs or made some configuration mistakes.

I've attached the images about the implementation. (Codes and Configuration). I'll be appreciated if you illuminate me about this problem. This is my first post on this web site so that please ignore my faults about this topic that I have )

Have a nice day..

1- ST I2C Slave Code

0693W000004JKqHQAW.png2- St CubeMx I2C Slave Configuration

0693W000004JKrEQAW.png3- Cypress I2C Master Functions

0693W000004JKrJQAW.png 

4- Cypress I2C Configuration

0693W000004JKrOQAW.png 

1 ACCEPTED SOLUTION

Accepted Solutions
HHOKE.1
Associate

Hi,

I've solved the problem by increasing the timeout values of I2C functions both on PSoC and ST side and changing I2CM_I2C_ACK_DATA to I2CM_I2C_NAK_DATA on PSoC side..I've updated the timeout values as 0xFF instead of 200 on both side. and I've set up the data rate of communication as 400khz as fast mode. Here's the functions that I have used for proper operation.

//PSoC I2C Master //

//Functions and Definitions//

#define I2C_TIMEOUT 0xFF

#define SLAVE_ADDR 0x43

void I2C_Write_Data(uint8_t Slave_Address, uint8_t I2C_Data)

{

    I2CM_I2CMasterSendStart(Slave_Address, I2CM_I2C_WRITE_XFER_MODE,I2C_TIMEOUT);

    I2CM_I2CMasterWriteByte(I2C_Data, I2C_TIMEOUT);

    I2CM_I2CMasterSendStop(I2C_TIMEOUT);

}

uint8_t I2C_Read_Data(uint8_t Slave_Address)

{

    uint8_t I2C_BUFFER = 0;

    I2CM_I2CMasterSendStart(Slave_Address, I2CM_I2C_READ_XFER_MODE,I2C_TIMEOUT);

    I2CM_I2CMasterReadByte(I2CM_I2C_NAK_DATA, &I2C_BUFFER, I2C_TIMEOUT);

    I2CM_I2CMasterSendStop(I2C_TIMEOUT);

    return I2C_BUFFER;

}

//Main_Function//

I2C_Write_Data(SLAVE_ADDR, 0xA0);

uint8_t I2C_RECEIVE_BUF = I2C_Read_Data(SLAVE_ADDR); // Returns the same data that's sent to the ST Slave. 0xA0.

//ST I2C Slave - Main Function//

uint8_t I2C_BUFFER = 0;

while(HAL_I2C_GetState(&hi2cs) != HAL_I2C_STATE_READY);

HAL_I2C_Slave_Receive(&hi2cs, &I2C_BUFFER, 1, HAL_MAX_DELAY);

switch(I2C_BUFFER)

{

    case 0xA0:

         uint8_t I2C_TRANSMIT_BUFFER = 0xA0;

         HAL_I2C_Slave_Transmit(&hi2cs, &I2C_TRANSMIT_BUFFER,1,HAL_MAX_DELAY);

    break;

}

View solution in original post

1 REPLY 1
HHOKE.1
Associate

Hi,

I've solved the problem by increasing the timeout values of I2C functions both on PSoC and ST side and changing I2CM_I2C_ACK_DATA to I2CM_I2C_NAK_DATA on PSoC side..I've updated the timeout values as 0xFF instead of 200 on both side. and I've set up the data rate of communication as 400khz as fast mode. Here's the functions that I have used for proper operation.

//PSoC I2C Master //

//Functions and Definitions//

#define I2C_TIMEOUT 0xFF

#define SLAVE_ADDR 0x43

void I2C_Write_Data(uint8_t Slave_Address, uint8_t I2C_Data)

{

    I2CM_I2CMasterSendStart(Slave_Address, I2CM_I2C_WRITE_XFER_MODE,I2C_TIMEOUT);

    I2CM_I2CMasterWriteByte(I2C_Data, I2C_TIMEOUT);

    I2CM_I2CMasterSendStop(I2C_TIMEOUT);

}

uint8_t I2C_Read_Data(uint8_t Slave_Address)

{

    uint8_t I2C_BUFFER = 0;

    I2CM_I2CMasterSendStart(Slave_Address, I2CM_I2C_READ_XFER_MODE,I2C_TIMEOUT);

    I2CM_I2CMasterReadByte(I2CM_I2C_NAK_DATA, &I2C_BUFFER, I2C_TIMEOUT);

    I2CM_I2CMasterSendStop(I2C_TIMEOUT);

    return I2C_BUFFER;

}

//Main_Function//

I2C_Write_Data(SLAVE_ADDR, 0xA0);

uint8_t I2C_RECEIVE_BUF = I2C_Read_Data(SLAVE_ADDR); // Returns the same data that's sent to the ST Slave. 0xA0.

//ST I2C Slave - Main Function//

uint8_t I2C_BUFFER = 0;

while(HAL_I2C_GetState(&hi2cs) != HAL_I2C_STATE_READY);

HAL_I2C_Slave_Receive(&hi2cs, &I2C_BUFFER, 1, HAL_MAX_DELAY);

switch(I2C_BUFFER)

{

    case 0xA0:

         uint8_t I2C_TRANSMIT_BUFFER = 0xA0;

         HAL_I2C_Slave_Transmit(&hi2cs, &I2C_TRANSMIT_BUFFER,1,HAL_MAX_DELAY);

    break;

}