This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EVMK2G: I2C_transfer fail , slave device PCA9555, device 0x20,Data Transfer failed with transfer status 259

Part Number: EVMK2G

#define I2C_EXP_INSTANCE 1
#define I2C_EXPIO_ADDR 0x20

/**********************************************************************
************************** Macros ************************************
**********************************************************************/

#define I2C_TRANSACTION_TIMEOUT (2000U)


/**********************************************************************
************************** Internal functions ************************
**********************************************************************/

/* Data compare function */
bool CompareData(char *expData, char *rxData, unsigned int length);

/**********************************************************************
************************** Global Variables **************************
**********************************************************************/


/*
* ======== Board_initI2C ========
*/
bool Board_initI2C(void)
{
Board_initCfg boardCfg;
Board_STATUS boardStatus;

I2C_HwAttrs i2c_cfg;

Board_SoCInfo socInfo;


/* Get the default I2C init configurations */
I2C_socGetInitCfg(I2C_EXP_INSTANCE, &i2c_cfg);

/* Modify the default I2C configurations if necessary */

/* Set the default I2C init configurations */
I2C_socSetInitCfg(I2C_EXP_INSTANCE, &i2c_cfg);


boardCfg = BOARD_INIT_PINMUX_CONFIG |
BOARD_INIT_MODULE_CLOCK |
BOARD_INIT_UART_STDIO;
boardStatus = Board_init(boardCfg);
if (boardStatus != BOARD_SOK)
{
return (false);
}


/* Read the SoC info to get the System clock value */
Board_getSoCInfo(&socInfo);
if(socInfo.sysClock != BOARD_SYS_CLK_DEFAULT)
{
/* Get the default I2C init configurations */
I2C_socGetInitCfg(I2C_EXP_INSTANCE, &i2c_cfg);
/* Update the I2C functional clock based on CPU clock - 1G or 600MHz */
i2c_cfg.funcClk = socInfo.sysClock/I2C_MODULE_CLOCK_DIVIDER;
/* Set the default I2C init configurations */
I2C_socSetInitCfg(I2C_EXP_INSTANCE, &i2c_cfg);
}

return (true);
}

/*
* ======== test function ========
*/
void i2c_test(void)
{
I2C_Params i2cParams;
I2C_Handle handle = NULL;
I2C_Transaction i2cTransaction;
char txBuf[3] = {0x2,0x00,00};
// char rxBuf[10] = {0x00, };
// bool status,test_pass=FALSE;
int16_t transferStatus;

I2C_init();

I2C_Params_init(&i2cParams);

handle = I2C_open(I2C_EXP_INSTANCE, &i2cParams);

I2C_transactionInit(&i2cTransaction);
i2cTransaction.slaveAddress = I2C_EXPIO_ADDR;
i2cTransaction.writeBuf = (uint8_t *)&txBuf[0];
i2cTransaction.writeCount = 3;
// i2cTransaction.readBuf = (uint8_t *)&rxBuf[0];
// i2cTransaction.readCount = I2C_EEPROM_TEST_LENGTH;
// i2cTransaction.timeout = I2C_TRANSACTION_TIMEOUT;
 transferStatus = I2C_transfer(handle, &i2cTransaction);

if(I2C_STS_SUCCESS != transferStatus)
{
I2C_log("\n Data Transfer failed with transfer status %d \n",transferStatus);

}

I2C_close(handle);


}

/*
* ======== main ========
*/
int main(void)
{
if (Board_initI2C() == false)
{
return (0);
}

i2c_test();

/* Start BIOS */
BIOS_start();
return (0);
}