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.

EK-TM4C123GXL: How to change the I2C interface?

Part Number: EK-TM4C123GXL


I am using the example program at ~\ccsv5\TivaWare_C_Series-1.0\examples\boards\ek-tm4c123gxl-boostxl-senshub\compdcm_mpu9150 in the Tivaware software. I want to change the I2C3 interface of mpu9150 to I2C1 interface. May you kindly teach me how to achieve this purpose?

Attachment is my program, Wish your step by step teaching for me.

#define MPU9150_I2C_ADDRESS  0x68

uint32_t g_pui32Colors[3];
tI2CMInstance g_sI2CInst;
tMPU9150 g_sMPU9150Inst;
tCompDCM g_sCompDCMInst;
volatile uint_fast8_t g_vui8I2CDoneFlag;
volatile uint_fast8_t g_vui8ErrorFlag;
volatile uint_fast8_t g_vui8DataFlag;
#define PRINT_SKIP_COUNT        10
uint32_t g_ui32PrintSkipCounter;
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
void
MPU9150AppCallback(void *pvCallbackData, uint_fast8_t ui8Status)
{
    if(ui8Status == I2CM_STATUS_SUCCESS)
    {
        g_vui8I2CDoneFlag = 1;
    }
    g_vui8ErrorFlag = ui8Status;
}
void
IntGPIOb(void)
{
    unsigned long ulStatus;

    ulStatus = GPIOIntStatus(GPIO_PORTB_BASE, true);

    GPIOIntClear(GPIO_PORTB_BASE, ulStatus);

    if(ulStatus & GPIO_PIN_2)
    {
        MPU9150DataRead(&g_sMPU9150Inst, MPU9150AppCallback, &g_sMPU9150Inst);
    }
}
void
MPU9150I2CIntHandler(void)
{
    I2CMIntHandler(&g_sI2CInst);
}
void
MPU9150AppErrorHandler(char *pcFilename, uint_fast32_t ui32Line)
{
    UARTprintf("\033[31;1m");
    UARTprintf("Error: %d, File: %s, Line: %d\n"
               "See I2C status definitions in sensorlib\\i2cm_drv.h\n",
               g_vui8ErrorFlag, pcFilename, ui32Line);
    UARTprintf("\033[0m");
    g_pui32Colors[0] = 0xFFFF;
    g_pui32Colors[1] = 0;
    g_pui32Colors[2] = 0;
    RGBColorSet(g_pui32Colors);
    RGBBlinkRateSet(10.0f);

    while(1)
    {
    }
}
void
MPU9150AppI2CWait(char *pcFilename, uint_fast32_t ui32Line)
{
    while((g_vui8I2CDoneFlag == 0) && (g_vui8ErrorFlag == 0))
    {
    }
    if(g_vui8ErrorFlag)
    {
        MPU9150AppErrorHandler(pcFilename, ui32Line);
    }
    g_vui8I2CDoneFlag = 0;
}

void
ConfigureUART(void)
{
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);
}

int
main(void)
{
    int_fast32_t i32IPart[16], i32FPart[16];
    uint_fast32_t ui32Idx, ui32CompDCMStarted;
    float pfData[16];
    float *pfAccel;

    pfAccel = pfData;

    ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    ConfigureUART();

    UARTprintf("\033[2JMPU9150 Raw Example\n");

    g_pui32Colors[RED] = 0x8000;
    g_pui32Colors[BLUE] = 0x8000;
    g_pui32Colors[GREEN] = 0x0000;

    RGBInit(0);
    RGBColorSet(g_pui32Colors);
    RGBIntensitySet(0.5f);
    RGBEnable();

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    ROM_GPIOPinConfigure(GPIO_PA6_I2C1SCL);
    ROM_GPIOPinConfigure(GPIO_PA7_I2C1SDA);

    GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
    ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);

    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2);  
    ROM_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE);  
    ROM_IntEnable(INT_GPIOB); 

    ROM_SysCtlPeripheralClockGating(true);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER1);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_I2C1);
    ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_WTIMER5);

    ROM_IntMasterEnable();

    I2CMInit(&g_sI2CInst, I2C1_BASE, INT_I2C1, 0xff, 0xff,
             ROM_SysCtlClockGet());

    MPU9150Init(&g_sMPU9150Inst, &g_sI2CInst, MPU9150_I2C_ADDRESS,
                MPU9150AppCallback, &g_sMPU9150Inst);

    MPU9150AppI2CWait(__FILE__, __LINE__);

    g_sMPU9150Inst.pui8Data[0] = MPU9150_CONFIG_DLPF_CFG_94_98;
    g_sMPU9150Inst.pui8Data[1] = MPU9150_GYRO_CONFIG_FS_SEL_250;
    g_sMPU9150Inst.pui8Data[2] = (MPU9150_ACCEL_CONFIG_ACCEL_HPF_5HZ |
                                  MPU9150_ACCEL_CONFIG_AFS_SEL_2G);
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_CONFIG, g_sMPU9150Inst.pui8Data, 3,
                 MPU9150AppCallback, &g_sMPU9150Inst);
    MPU9150AppI2CWait(__FILE__, __LINE__);
    g_sMPU9150Inst.pui8Data[0] = MPU9150_INT_PIN_CFG_INT_LEVEL |
                                    MPU9150_INT_PIN_CFG_INT_RD_CLEAR |
                                    MPU9150_INT_PIN_CFG_LATCH_INT_EN;
    g_sMPU9150Inst.pui8Data[1] = MPU9150_INT_ENABLE_DATA_RDY_EN;
    MPU9150Write(&g_sMPU9150Inst, MPU9150_O_INT_PIN_CFG,
                 g_sMPU9150Inst.pui8Data, 2, MPU9150AppCallback,
                 &g_sMPU9150Inst);
    MPU9150AppI2CWait(__FILE__, __LINE__);
    CompDCMInit(&g_sCompDCMInst, 1.0f / 50.0f, 0.2f, 0.6f, 0.2f);

    UARTprintf("MPU9150 9-Axis Simple Data Application Example\n\n");
    UARTprintf("Accel\033[8G|\033[31G|\033[54G|\n\n");
    RGBBlinkRateSet(1.0f);

    ui32CompDCMStarted = 0;

    while(1)
    {
        while(!g_vui8I2CDoneFlag)
        {
            ROM_SysCtlSleep();
        }
        g_vui8I2CDoneFlag = 0;
        MPU9150DataAccelGetFloat(&g_sMPU9150Inst, pfAccel, pfAccel + 1,
                                 pfAccel + 2);
        if(ui32CompDCMStarted == 0)
        {
            ui32CompDCMStarted = 1;
            CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
                               pfAccel[2]);
            CompDCMStart(&g_sCompDCMInst);
        }
        else
        {
            CompDCMAccelUpdate(&g_sCompDCMInst, pfAccel[0], pfAccel[1],
                               pfAccel[2]);
            CompDCMUpdate(&g_sCompDCMInst);
        }
        g_ui32PrintSkipCounter++;
        if(g_ui32PrintSkipCounter >= PRINT_SKIP_COUNT)
        {
            g_ui32PrintSkipCounter = 0;
            for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
            {
                i32IPart[ui32Idx] = (int32_t) pfData[ui32Idx];
                i32FPart[ui32Idx] = (int32_t) (pfData[ui32Idx] * 1000.0f);
                i32FPart[ui32Idx] = i32FPart[ui32Idx] -
                                    (i32IPart[ui32Idx] * 1000);
                if(i32FPart[ui32Idx] < 0)
                {
                    i32FPart[ui32Idx] *= -1;
                }
            }
            UARTprintf("\033 x:%3d.%03d", i32IPart[0], i32FPart[0]);
            UARTprintf("\033 y:%3d.%03d", i32IPart[1], i32FPart[1]);
            UARTprintf("\033 z:%3d.%03d", i32IPart[2], i32FPart[2]);
        }
    }
}

  • I did a quick comparison of the code which you posted against the example. It looks like you properly changed references from I2C3 to I2C1. Also you configured the proper pins PA6 instead of PD0 and PA7 instead of PD1. How did you change the hardware connection between the EK-TM4C123GXL and the sensor hub, or are you using a custom board? Did you update the interrupt vector table in "startup_ccs.c"?