Hi,
I'm trying to read TMP101 using I2C1 of TM4C123FH6PM. But i'm always getting '0' value. Following is my code.
//uart initialization
void uart_init(void)
{
//
// Initialize the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);
UARTprintf("Hello, world!\n");
}
// i2c init
void i2c_init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PA6_I2C1SCL);
GPIOPinConfigure(GPIO_PA7_I2C1SDA);
GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
HWREG(I2C1_MASTER_BASE + I2C_O_MCR) |= 0x01;
I2CMasterInitExpClk(I2C1_MASTER_BASE, SysCtlClockGet(), false);
I2CSlaveEnable(I2C1_SLAVE_BASE);
I2CSlaveInit(I2C1_SLAVE_BASE, SLAVE_ADDRESS);
I2CMasterSlaveAddrSet(I2C1_MASTER_BASE, SLAVE_ADDRESS, false);
}
main(void)
{
unsigned long i;
unsigned long ulRecData;
unsigned long ulMasterData[2] = {0x00, 0xAA};
FPUEnable();
FPULazyStackingEnable();
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
uart_init();
i2c_init();
I2CMasterDataPut(I2C1_MASTER_BASE, ulMasterData[0]);
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
// while(I2CMasterBusBusy(I2C_MASTER_BASE))
{
}
I2CMasterDataPut(I2C1_MASTER_BASE, ulMasterData[1]);
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
// while(I2CMasterBusBusy(I2C_MASTER_BASE))
{
}
/* Read the data */
I2CMasterSlaveAddrSet(I2C1_MASTER_BASE, SLAVE_ADDRESS, true);
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
// while(I2CMasterBusBusy(I2C_MASTER_BASE))
{
}
ulRecData = I2CMasterDataGet(I2C1_MASTER_BASE);
UARTprintf(" Data Received: %4d\n", ulRecData);
while(1)
{
for(i=0;i<60000;i++)
{
if(i==59999)
{
I2CMasterControl(I2C1_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
ulRecData = I2CMasterDataGet(I2C1_MASTER_BASE);
UARTprintf(" Data Received: %4d\n", ulRecData);
}
}
}
}
Also, if i use
while(I2CMasterBusBusy(I2C_MASTER_BASE)) {}
the code is getting stuck there.
Any solution for this.
Any help is much appreciated
-Bijo