Tool/software: TI-RTOS
I have set a sensor LTC4151 at address 0xD0 tied to I2C1 interface of Tiva as master. I am attaching a simple code where I send the address of the register I wish to read from the LTC4151 to the slave LTC4151 device
I see that the code I used has been tried by others but I am not able to read data
#define SLAVE_ADDRESS 0xD0 // Address appears from bits 7:1 D0 shifted 1 place to right is 68
#define NUM_OF_I2CBYTES 2
//*****************************************************************************
//
// Main Program to Configure and Use the I2C Master I2C1
//
//*****************************************************************************
int
main(void)
{
// Setup System Clock for 120MHz
//
ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_XTAL_25MHZ |
SYSCTL_CFG_VCO_480), 120000000);
// Enable GPIO for Configuring the I2C Interface Pins
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
// Wait for the Peripheral to be ready for programming
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOG));
//
// Configure Pins for I2C1 Master Interface
//
GPIOPinConfigure(GPIO_PG0_I2C1SCL);
GPIOPinConfigure(GPIO_PG1_I2C1SDA);
GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_1);
GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_0);
//
// Stop the Clock, Reset and Enable I2C Module
// in Master Function
//
SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
//
// Wait for the Peripheral to be ready for programming
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C1));
// Initialize and Configure the Master Module
//
I2CMasterInitExpClk(I2C1_BASE, ui32SysClock, true);
// --------------------------To Write before read-----------------------
I2CMasterSlaveAddrSet (I2C1_BASE, SLAVE_ADDRESS, false); //set slave address and initiate with write
I2CMasterControl (I2C1_BASE, I2C_MASTER_CMD_SINGLE_SEND); //Send STOP bit
I2CMasterDataPut (I2C1_BASE, 0x00); //Put 0x00 -- send address of register to be read from SLAVE
while (!(I2CMasterBusy(I2C1_BASE))); //Wait till end of transaction
// while ((I2CMasterBusy(I2C1_BASE))); //Wait till end of transaction
I2CMasterSlaveAddrSet (I2C1_BASE, SLAVE_ADDRESS, true); //set slave address and initiate with read
I2CMasterControl (I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); //Read the 1st Byte
pui32DataRx[0] = I2CMasterDataGet(I2C1_BASE);
while (!(I2CMasterBusy(I2C1_BASE))); //Wait till end of transaction
// while ((I2CMasterBusy(I2C1_BASE))); //Wait till end of transaction
I2CMasterControl (I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); //Read the 2nd Byte
pui32DataRx[1] = I2CMasterDataGet(I2C1_BASE);
while (!(I2CMasterBusy(I2C1_BASE))); //Wait till end of transaction
// while ((I2CMasterBusy(I2C1_BASE))); //Wait till end of transaction
while (1)
{
}
} //end main