Part Number: TM4C123GH6PM
Hi,
I2C is not reading registers on intial power up, but if i debugged once then its working as expected in all the next runs.
I'm using CCSv8.1, Windows 10, EK - TM4C123GXL
I2C0 Channel I'm using for I2C Communication.
I2C0 SCL - PB2
I2C0 SDA - PB3
Here i attached my code snippets:
/* Check that I2C SDA is not being held low If so, toggle I2C SCL until it is released
* Safe for i2c Communication when Reset button is pressed */
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_3);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2);
while (GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_3) != GPIO_PIN_3)
{
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, 0);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_PIN_2);
}
Initializing I2c:
/* I2C0 Init */
/* Enable the peripheral */
SysCtlPeripheralEnable (SYSCTL_PERIPH_I2C0);
// Configure the GPIO Pin Mux for PB2 for I2C0SCL
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
// Configure the GPIO Pin Mux for PB3 for I2C0SDA
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
I'm using TI-RTOS 2.16.00.08 for my project configured below function as Task to get the data from IMU Sensor:
void get_imu()
{
I2C_Handle i2c;
I2C_Params i2cParams;
uint8_t pwr;
pwr = 0x00;
//Create I2C for usage
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(IMU_SENSOR, &i2cParams);
if (i2c == NULL)
{
System_abort("Error Initializing I2C\n");
}
else
{
System_printf("I2C Initialized!\n");
}
// Initialize the MPU6050
writeRegister(i2c, 0x6B, 0x80, true);
readRegister(i2c, 0x6B, &pwr, 1, true);
do
{
readRegister(i2c, 0x6B, &pwr, 1, true);
}
while (pwr & 0x40 != 0x40);
// Use PLL with X axis gyroscope reference
writeRegister(i2c, 0x6B, 0x01, true);
// Enable I2C Master mode
writeRegister(i2c, 0x6A, 0x20, true);
// Set sample rate divider
writeRegister(i2c, 0x19, 0x13, true);
writeRegister(i2c, 0x67, 0x11, true);
while (1)
{
Semaphore_pend(IMUSem, BIOS_WAIT_FOREVER);
readRegister(i2c, 0x3B, (uint8_t *) &signal.imu.mpu6050, 14, true);
}
//Deinitialized I2C
I2C_close(i2c);
System_printf("I2C closed!\n");
System_flush();
}
Regards,
Yashwanth Kumar Gandeti.



