Other Parts Discussed in Thread: TM4C123GH6PM
Hello,
I'm trying to communicate between the TM4C123G Launchpad and a GY52 breakout board with an MPU6050.
The sensor's I2C SDA is connected to PE4 and the SCL to PE5.
The sensor is powered from the 5V pin of Launchpad (an LDO converts the 5V to 3.3V to power the MPU6050).
Please see the attached photo:
Blue wire: SDA
Black wire: SCL
Red wire: 5V VCC
Green wire: GND
I tested to see that the board's LDO functions correctly and I measured exactly 3.3V.
I use the following code and run it line by line using F6 in CCS.
It gets stuck on the line with the MPU6050Init function.
//////////////////////////////////////////////////////////////////////////////////////////////////// #include <stdbool.h> #include <stdint.h> #include "driverlib/debug.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/pwm.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "inc/hw_gpio.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" //////////////////////////////////////////////////////////////////////////////////////////////////// // My I2C defines & includes #include "driverlib/i2c.h" #include "driverlib/interrupt.h" #include "inc/hw_i2c.h" #include "inc/hw_ints.h" #include "sensorlib/i2cm_drv.h" #include "sensorlib/mpu6050.h" #include "sensorlib/hw_mpu6050.h" #define DEBUG //////////////////////////////////////////////////////////////////////////////////////////////////// #include "definitions_mpu6050.h" tI2CMInstance g_sI2CInst; // I2C master driver structure. "tI2CMInstance" is defined in the i2cm_drv.h file. tMPU6050 g_sMPU6050Inst; // MPU6050 sensor driver structure. "tMPU6050" is defined in the mpu6050.h file. volatile unsigned long g_vui8DataFlag; // Data ready flag volatile unsigned long g_vui8ErrorFlag; // Error flag //////////////////////////////////////////////////////////////////////////////////////////////////// int main(void) { // Configure the clock SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //////////////////////////////////////////////////////////////////////////////////////////////////// // My I2C initialization code // Enable GPIO peripheral that contains I2C 2 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // Enable I2C module 2 SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2); // Configure the pin muxing for I2C2 functions on port E4 and E5. GPIOPinConfigure(GPIO_PE4_I2C2SCL); GPIOPinConfigure(GPIO_PE5_I2C2SDA); // Select the I2C function for these pins. GPIOPinTypeI2CSCL(GPIO_PORTE_BASE, GPIO_PIN_4); GPIOPinTypeI2C(GPIO_PORTE_BASE, GPIO_PIN_5); IntMasterEnable(); I2CMInit(&g_sI2CInst, I2C2_BASE, INT_I2C2, 0xFF, 0xFF, SysCtlClockGet()); SysCtlDelay(SysCtlClockGet() / 3); float fAccel[3], fGyro[3]; // USER_MPU6050Callback will modify the g_bMPU6050Done variable to true if MPU6050Init succeeds. g_bMPU6050Done = false; // Initialize the MPU6050 MPU6050Init(&g_sMPU6050Inst, &g_sI2CInst, MPU6050_I2C_ADDRESS, USER_MPU6050Callback, &g_sMPU6050Inst); while(!g_bMPU6050Done) { } // USER_MPU6050Callback will modify the g_bMPU6050Done variable to true if MPU6050ReadModifyWrite succeeds. g_bMPU6050Done = false; // Configure the MPU6050 for +/- 4 g accelerometer range. MPU6050ReadModifyWrite(&g_sMPU6050Inst, MPU6050_O_ACCEL_CONFIG, ~MPU6050_ACCEL_CONFIG_AFS_SEL_M, MPU6050_ACCEL_CONFIG_AFS_SEL_4G, USER_MPU6050Callback, 0); while(!g_bMPU6050Done) { } while(1) { } }