Other Parts Discussed in Thread: EK-TM4C123GXL
Hi all,
I am trying to communicate with a H3LIS331DL accelerometer. Upon sending the very first Start and Slave address, the I2C0 bus becomes busy and is not able to exit the loop. I've checked out most of the threads but I still can't solve this problem. Does anyone have any suggestions ? I'm using CCS 5.2.1 and LM4F232 Evaluation board. Thanks.
Regards,
Tian Hao
Link to the accelerometer: http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00053090.pdf
#define I2C_ACCELEROMETER_ADDRESS 0x30
#define I2C_ACCELEROMETER_X_AXIS_L 0x28
#define NUM_I2C_DATA 512
static char DataRx[NUM_I2C_DATA];
// Init Code.
void
accelerometerI2CConfigure(void)
{
// Enable I2C Module.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
// Enable GPIO used.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
// Configure Pins for I2C function and open-drain operation with weak
// pull-ups.
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
// Use the system clock for the I2C module. Set the I2C data transfer rate to 100kbps.
ROM_I2CMasterInitExpClk(I2C0_MASTER_BASE, ROM_SysCtlClockGet(), false);
return;
}
// Read
void
readAccelerometerI2C(void)
{
// Tell the master module what address it will place on the bus when
// communicating with the slave.
ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE,
I2C_ACCELEROMETER_ADDRESS>>1,
false);
// Write SUB to data register.
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, I2C_ACCELEROMETER_X_AXIS_L);
// Send a start condition, slave address and first byte.
ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
// Loop until transfer complete.
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE));
// Set slave address with receive operation.
ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE,
I2C_ACCELEROMETER_ADDRESS>>1,
true);
// Send address again with repeated start condition.
ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
// Loop until transfer complete.
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE));
// Read data.
DataRx[0] = ROM_I2CMasterDataGet(I2C0_MASTER_BASE);
return;
}