Hello All,
I am trying to use the I2C bus to communicate with an IMU (M9250) and I am running into issues with my write functions. For some reason my I2C master bus is never being freed. I stay and wait for it to no longer be busy indefinitely. Below is the code in question. I am stuck in the while loop where I wait for the I2C to not be busy. Could this be due to the I2C slave not responding to me?
void
i2c_initialize(void)
{
// Configure I2C Communication
MAP_SysCtlPeripheralEnable(MCU_IMU_I2C_SCL_SYSCTL_PERIPH);
MAP_GPIOPinConfigure(MCU_IMU_I2C_SDA_PINCONFIG);
MAP_GPIOPinTypeI2C(MCU_IMU_I2C_SDA_GPIO_PORT_BASE,MCU_IMU_I2C_SDA_GPIO_PIN);
MAP_GPIOPinConfigure(MCU_IMU_I2C_SCL_PINCONFIG);
MAP_GPIOPinTypeI2CSCL(MCU_IMU_I2C_SCL_GPIO_PORT_BASE,MCU_IMU_I2C_SCL_GPIO_PIN);
// I2C Setup
MAP_SysCtlPeripheralEnable(MCU_IMU_I2C_SYSCTL_PERIPH);
I2CMasterEnable(MCU_IMU_I2CBASE);
SysCtlPeripheralReset(MCU_IMU_I2C_SCL_SYSCTL_PERIPH);
I2CMasterInitExpClk(MCU_IMU_I2CBASE, g_sysClkFreq, true);
}
static uint8_t
imu_i2cWrite(uint8_t slaveAddress , uint8_t* data, uint8_t length, bool repeated)
{
I2CMasterSlaveAddrSet(MCU_IMU_I2CBASE, slaveAddress, false);
I2CMasterDataPut(MCU_IMU_I2CBASE, *data++);
if (length < 2)
{
if (repeated)
{
I2CMasterControl(MCU_IMU_I2CBASE, I2C_MASTER_CMD_BURST_SEND_START);
}
else
{
I2CMasterControl(MCU_IMU_I2CBASE, I2C_MASTER_CMD_SINGLE_SEND);
}
while(!(I2CMasterBusy(MCU_IMU_I2CBASE)));
while(I2CMasterBusy(MCU_IMU_I2CBASE));
}
else
{
I2CMasterControl(MCU_IMU_I2CBASE, I2C_MASTER_CMD_BURST_SEND_START);
length--;
POLLI2C(MCU_IMU_I2CBASE);
while(length)
{
I2CMasterDataPut(MCU_IMU_I2CBASE, *data++);
if (!repeated && (length == 1))
{
I2CMasterControl(MCU_IMU_I2CBASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
}
else
{
I2CMasterControl(MCU_IMU_I2CBASE, I2C_MASTER_CMD_BURST_SEND_CONT);
}
length--;
while(!(I2CMasterBusy(MCU_IMU_I2CBASE)));
while(I2CMasterBusy(MCU_IMU_I2CBASE));
}
}
return 0;
}
Regards,
Bryan