Hi,
Sorry for re-posting the same query again, I need urgent support on I2C initialization. Please let me know if further information is required.
I am working on evaluation board LM4F232H5QD where I2C0 is connected to TMP75 temperature sensor. I am using the following code:
1) To initialize I2C0
void InitI2C0(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false); // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
// SYSCTL_XTAL_16MHZ);
}
2) Code to send data:
void I2C_burstsend(unsigned char ucSlaveAddr, unsigned char sendData[], unsigned char size)
{
unsigned int i;
// Set the slave address, and set the Master to Transmit mode
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, ucSlaveAddr, false);
// Place the character to be sent in the data register
I2CMasterDataPut(I2C0_MASTER_BASE, sendData[0]);
// Initiate send of character from Master to Slave
if (size > 0)
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
else
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
// Delay until transmission completes
while(I2CMasterBusy(I2C0_MASTER_BASE)){}
if (size == 0)
return;
// send data array
for(i=1; i < (size-1); i++)
{
I2CMasterDataPut(I2C0_MASTER_BASE, sendData[i]);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C0_MASTER_BASE)){}
}
// send the last byte
I2CMasterDataPut(I2C0_MASTER_BASE, sendData[i]);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_MASTER_BASE)){}
}
It seems the code is not working, when I put a breakpoint at "if (size > 0)" and check the value of Register in CCS5 I2C0->I2C_MDR->I2C_MDR_DATA, the value is 0x00000000; the value of sendData[0] = 0x90.
When I proceed to next step i.e. I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START); and checked the value of I2C_MCS_ERROR, its value is 1.
FYI, TMP75 is connected with 4.7kohm pull-up resistor.
Looking forward to your support.
Thanks and regards,
Praveen
// -------------------------------------------
I also tried the following code to initialize the I2C0, but behaviour is same:
void InitI2C0(void)
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
I2CMasterIntEnable(I2C0_MASTER_BASE);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU);
ROM_I2CMasterInitExpClk(I2C0_MASTER_BASE, ROM_SysCtlClockGet(), false);
}