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.