This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS: MPU6050 Sensorlib

Tool/software: Code Composer Studio

Hello,

I'm Using TM4C123G board and I have followed the example given in the 'SW-TM4C-SENSORLIB-UG-1.1.pdf' for interfacing MPU6050, But I'm facing trouble in generating the I2C communication. Is that example is enough or should I extra line for communication. If yes then can you please mention the changes that I have to make.  

  • Hello Vishnu,

    First of all check if the I2C lines are high when the bus is idle after the I2C configuration, but before any transaction is started?

    If both SCL and SDA are high, then capture the scope plots of SCL and SDA to see how transactions are being processed between the micro-controller and the MPU6050 device.
  • Hello,
    I'm struggling with MPU configuration

    void MPUInitialize (void)
    {
    g_bMPU6050Done = false;
    MPU6050Init(&sMPU6050, &sI2CInst, 0x68, MPU6050Callback, 0);
    while(!g_bMPU6050Done);  
    // config MPU for +/- 4 g accelerometer range
    //g_bMPU6050Done = false;
    MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_ACCEL_CONFIG, ~MPU6050_ACCEL_CONFIG_AFS_SEL_M,
    MPU6050_ACCEL_CONFIG_AFS_SEL_4G, MPU6050Callback, 0);
    while(!g_bMPU6050Done);

    //config MPU +- 500 d/sec Gyro range
    g_bMPU6050Done = false;
    MPU6050ReadModifyWrite(&sMPU6050, MPU6050_O_GYRO_CONFIG, ~MPU6050_GYRO_CONFIG_FS_SEL_M,
    MPU6050_GYRO_CONFIG_FS_SEL_500, MPU6050Callback, 0);
    while(!g_bMPU6050Done);
    }

    which is declared in the main.c but MPU6050Callback function is declared as static in MPU6050.c. I can not actually call them. I tried by passing NULL I think it also not working properly. One more thing how exactly I can find out which I2c I'm using (I2C1, I2C2, or I2C3) 

    Thank you,
    Vishnu

  • Hello Vishnu,

    Check the sI2CInst structure. It should tell you which I2C is being used. Also as I mentioned earlier, based on which I2C module is being used, check the I2C signals SCL and SDA corresponding to it to be Idle.
  • Hello,

    Sorry for asking this basic question, since I'm new to this field how can I check for SCL and SDA corresponding to it to be Idle.

    void I2C1Init(void)
    {
    	//clok
    	Clock = SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 12000000);
    	// Enable clock for I2C module 1
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
    	//Reset module
    	SysCtlPeripheralReset(SYSCTL_PERIPH_I2C1);
    	// Enable the ports that contain module 1#
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    	//config the pins for I2C
    	GPIOPinConfigure(GPIO_PA6_I2C1SCL);
    	GPIOPinConfigure(GPIO_PA7_I2C1SDA);
    	//Select I2C function for the pins
    	GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
    	GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
    	// enable and initialize I2C1 master module use system clock
    	//the I2C1 module. I2C1 Transfer rate is set to 400kbps
    	I2CMasterInitExpClk(I2C1_BASE, Clock, true);
    	//clear I2C fifos
    	HWREG(I2C1_BASE + I2C_O_FIFOCTL) = 80008000;
    	//I2CMInit(&sI2CInst, I2C1_BASE, INT_I2C1, 0xff, 0xff, Clock);
    }

    This is my I2C Initialization. The problem I'm facing is every time I debug the code on TM4C123G debugger will be halted in while loop.

    g_bMPU6050Done = false;
    MPU6050Init(&sMPU6050, &sI2CInst, 0x68, MPU6050Callback, 0);
    while(!g_bMPU6050Done);

    I have read many articles but I'm not able to find any good answers can please help me.

    thank you,

  • Also, I would like to know is there any mistakes that I'm doing in the I2C initialization.
  • Hello Vishnu

    The initialization looks correct. I would suggest referring to the I2C Application Note as a self read for TM4C129x devices for understanding the protocol and the implementation.

    www.ti.com/.../spma073.pdf
  • Hello Amit Ashara,

    Thank you for all the support, I was able to understand more clearly now. But during the debug I found out that MPU6050 initialization not successful.

    as you can see in the above picture the

    MPU6050Init(&sMPU6050, &sI2CInst, 0x68, MPU6050Callback, 0);

    function returns zero. So the first initialisation its self is having some trouble.  Hence I thought of replacing 'MPU6050Callback' with NULL, it also works in the same way. Is there any way that you can help me. I have also followed your conversation in below link

     

    Thank You.

    Vishnu

     

  • Hello Vishnu,

    Did you check for what conditions dos the function return 0? In other words a 0 return code is for which error?