Tool/software:
Dear TI Team,
We are working on the I2C protocol at TMS320C6678's EVM. We are using the I2C to write and read on the EEPROM. We transmitted the data on EEPROM successfully by Master.
But, We still have not received (retrieved) data from the slave.
PFA, for the code review, if there is any issue or missing MASK or CFN, CMD or something else please provide us with some resolution on it.
void main() { I2CMasterInit(I2CR,EEPROM_I2C_SLAVE_ADDR,I2C_OWN_ADDR); //I2CSlaveInit(I2CR,I2C_OWN_ADDR,EEPROM_I2C_SLAVE_ADDR); while(1){ I2C_EEPROM_TEST(); } } void I2C_EEPROM_TEST(void) { int i,j; uint8_t writeData[] = {0x12, 0x34, 0x56, 0x78}; // Example data to write uint8_t readData[4]; // Buffer to store read data EEPROMWrite(I2CR, EEPROM_I2C_SLAVE_ADDR, writeData, sizeof(writeData)); EEPROMRead(I2CR, EEPROM_I2C_SLAVE_ADDR, readData, sizeof(readData)); // Print the read data printf("Read data from EEPROM:\n"); for (i= 0; i < sizeof(readData); i++) { printf("Data %d: 0x%02X\n", i, readData[i]); } // Print the Write data printf("Write data from EEPROM:\n"); for (j= 0; j < sizeof(writeData); j++) { printf("Data %d: 0x%02X\n", j, writeData[j]); } } void I2CMasterInit(CSL_I2cRegsOvly i2c,uint32_t slavAdd,uint32_t ownAddr){ I2CMasterDisable((uint32_t)i2c); I2CMasterInitExpClk((uint32_t)i2c,166660000,1000000000,8000000); /* Set I2C slave address. */ I2COwnAddressSet((uint32_t)i2c,ownAddr); I2CMasterEnable((uint32_t)i2c); I2CSlaveEnable((uint32_t)i2c); I2CMasterStart((uint32_t)i2c); } // Function to initialize I2C slave void I2CSlaveInit(CSL_I2cRegsOvly i2c,uint32_t ownAddr,uint32_t slavAdd) { I2COwnAddressSet((uint32_t)i2c,ownAddr); I2CSlaveEnable(slavAdd); } void EEPROMWrite(CSL_I2cRegsOvly i2c, uint32_t address, uint8_t *data, uint32_t length) { uint32_t i ; I2CMasterSlaveAddrSet((uint32_t)i2c, address); // Set data count I2CSetDataCount((uint32_t)i2c, length + 2); // +2 for EEPROM address I2CMasterControl((uint32_t)i2c,I2C_CFG_MASK_TX|I2C_CFG_MASK_START,I2C_CFG_CMD_TX|I2C_CFG_CMD_START); // Send the EEPROM address (high byte and low byte) I2CMasterDataPut((uint32_t)i2c, (address >> 8) & 0xFF); I2CMasterDataPut((uint32_t)i2c, address & 0xFF); // Send data bytes for (i = 0; i < length; i++) { I2CMasterDataPut((uint32_t)i2c,data[i]); } I2CMasterControl((uint32_t)i2c,I2C_CFG_MASK_TX|I2C_CFG_MASK_START,I2C_CFG_CMD_TX|I2C_CFG_CMD_START); I2CMasterStop((uint32_t)i2c); // Stop the I2C transmission I2CMasterControl((uint32_t)i2c, I2C_CFG_MASK_STOP, I2C_CFG_CMD_STOP); } void EEPROMRead(CSL_I2cRegsOvly i2c, uint32_t address, uint8_t *data, uint32_t length) { uint32_t i; I2CMasterSlaveAddrSet( (uint32_t)i2c, address); // Set data count I2CSetDataCount((uint32_t)i2c, 2); // +2 for EEPROM address // Start the I2C transmission to write the EEPROM address I2CMasterControl((uint32_t)i2c, I2C_CFG_MASK_TX | I2C_CFG_MASK_START, I2C_CFG_CMD_TX | I2C_CFG_CMD_START); // Send the EEPROM address (high byte and low byte) I2CMasterDataPut((uint32_t)i2c, (address >> 8) & 0xFF); I2CMasterDataPut((uint32_t)i2c, address & 0xFF); // Start the I2C reception I2CMasterControl((uint32_t)i2c, I2C_CFG_MASK_RX | I2C_CFG_MASK_START | I2C_CFG_MASK_STOP, I2C_CFG_CMD_RX | I2C_CFG_CMD_START | I2C_CFG_CMD_STOP); // Set data count I2CSetDataCount((uint32_t)i2c, length); // +2 for EEPROM address // Read data bytes for ( i= 0; i < length; i++) { data[i] = I2CMasterDataGet((uint32_t)i2c); } }
Warmest regards,
Krishn Singh Chauhan