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.

CCS/tm4c129encpdt: I2C not working fine

Part Number: TM4C129ENCPDT

Tool/software: Code Composer Studio

Dear all,

I used the below code to read a slave device of address 0x40 and to write a byte. But its not working. I just need a read and rit to be performed from a slave device(IO expander)

void I2C6Init(void)
{
	/**************I2C************************/
	//
	// The I2C6 peripheral must be enabled before use.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);


	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);


	GPIOPinConfigure(GPIO_PA6_I2C6SCL);
	GPIOPinConfigure(GPIO_PA7_I2C6SDA);


	GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
	GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);

	// HWREG(I2C6_BASE + I2C_O_MCR) |= 0x01;

	//
	// Enable the I2C6 interrupt on the processor (NVIC).
	//
	IntEnable(INT_I2C6);

	//
	// Configure and turn on the I2C6 slave interrupt.
	I2CSlaveIntEnableEx(I2C6_BASE, I2C_SLAVE_INT_DATA);

	//#if defined(TARGET_IS_TM4C129_RA0) || \
	// defined(TARGET_IS_TM4C129_RA1) || \
	// defined(TARGET_IS_TM4C129_RA2)
	I2CMasterInitExpClk(I2C6_BASE, g_ui32SysClock, false);
	//#else
	// I2CMasterInitExpClk(I2C6_BASE, SysCtlClockGet(), false);
	//#endif


	I2CSlaveEnable(I2C6_BASE);


	I2CSlaveInit(I2C6_BASE, SLAVE_ADDRESS);


	//I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);
}



void ioWrite(uint8_t data_u8)
{


	I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, false);
	//
	// Place the data to be sent in the data register
	//
	I2CMasterDataPut(I2C6_BASE, data_u8);

	//
	// Initiate send of data from the master.
	//
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_SINGLE_SEND);

	//
	// Wait until the slave has received and acknowledged the data.
	//
	while(!(I2CSlaveStatus(I2C6_BASE) & I2C_SLAVE_ACT_RREQ))
	{
	}
}






int ioRead(void)
{
	int data[2]=0;
	//
	// Modifiy the data direction to true, so that seeing the address will
	// indicate that the I2C Master is initiating a read from the slave.
	//
	I2CMasterSlaveAddrSet(I2C6_BASE, SLAVE_ADDRESS, true);

	//
	// Tell the master to read data.
	//
	I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

	//
	// Wait until the slave is done sending data.
	//

	while(!(I2CSlaveStatus(I2C6_BASE) & I2C_SLAVE_ACT_TREQ))
	{
	}

	//
	// Read the data from the master.
	//
	data[0]= (I2CMasterDataGet(I2C6_BASE));

	return data;

}

kindly help me.

  • First, I took the liberty of editing your post and formatting the code you posted using the </> button. It makes the code much easier to read and is more likely to be reviewed by one of the experienced user's who volunteer their time to help.

    You mentioned that you want to "read a slave device of address 0x40", however you configured the TM4C129ENCDT to be a slave. The TM4C must be a master if it is to read a slave.

  • Good job, Bob - nice concise analysis.

    Pity that most always - posters' claim that, TM4C's xyz "Not working fine" - when in fact it most always IS!

    Inevitably - as will surely be revealed here - it is poster's understanding & implementation which proves, "Not working fine!"
    In our field - where a "missing or extraneous ";" can wreak havoc - correct definition of poster issues should be "Job One!"