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.

MSP-EXP432E401Y: I used MSP432E401Y to read data from the MPU6050 sensor, but nothing displayed.

Part Number: MSP-EXP432E401Y
Other Parts Discussed in Thread: MSP432E401Y, SYSCONFIG

Hello everyone,

I just wrote C code for MSP432E401Y to read data from the MPU6050 sensor. The code is built and flashed with no errors.

I configured the MPU6050 directly to the MSP432E401Y for I2C as follows:



VCC ----V3V

GND ----- GND

SCL ------- PD2

SDA ------ PD3

I use PuTTY for UART display

It supposed to show the Accelerometer, Gyro and Temperature,  but unfortunately, I did not see any displayed result 


The following is some part of the code that displays information about sensor data.

// I2C CONFIG
I2C_Params_init(&mpu6050Params);
mpu6050Params.bitRate = I2C_400kHz;
mpu6050Params.transferMode = I2C_MODE_BLOCKING;
mpu6050Handle = I2C_open(CONFIG_I2C_0, &mpu6050Params);

MPU6050_Reset();

while (1)
{
MPU6050_ReadData(accel_data, gyro_data, &temperature);

// Display sensor data on UART

Display_print3(uartHandle, 0, 0, "Accelerometer X_AXIS=%d Y_AXIS=%d Z_AXIS=%d\r\n", accel_data[0], accel_data[1], accel_data[2]);
Display_print3(uartHandle, 1, 0, "Gyroscope X_AXIS=%d Y_AXIS=%d Z_AXIS=%d\r\n", gyro_data[0], gyro_data[1], gyro_data[2]);
Display_printf(uartHandle, 2, 0, "Temperature = %.2f °C\r\n", (float)(temperature / 340.0) + 36.53);

// Sleep for a shorter duration (adjust as needed)
usleep(100000); // sleep for 100,000 microseconds (0.1 seconds)
}
}

 
 

  • Set a breakpoint to make sure you are getting the data.

    Do you have a "Hello, World!" sent out via serial at the start to make sure that you are sending serial data?

    Put a scope on the I2C lines to make sure there is activity.

  • Hi,

      On top of Keith's feedback, please also check you have the correct baudrate, stop bits and no parity between your terminal window and the UART0 setting. 

      I suppose you have a valid handle on uartHandle. Is that correct? You need to make sure a valid uartHandle is acquired. Did you call Display_init() before you open the UART display?

      Please reference the example at C:\ti\simplelink_msp432e4_sdk_4_20_00_12\examples\rtos\MSP_EXP432E401Y\drivers\i2ctmp.

  • Here is the Code:

    #include <stdint.h>
    #include <stddef.h>
    #include <unistd.h>
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/I2C.h>
    #include <ti/display/Display.h>
    #include <ti/display/DisplayUart.h>
    #include "ti_drivers_config.h"

    // Declare to read data declare global variable
    I2C_Params mpu6050Params;
    I2C_Handle mpu6050Handle;
    I2C_Transaction mpu6050Transaction = {0};

    void MPU6050_Reset();
    void MPU6050_ReadData(int16_t accel_data[3], int16_t gyro_data[3], int16_t *temperature);

    #define MPU6050_ADDRESS (0x68) // Corrected the definition

    void *mainThread(void *arg0)
    {
    int16_t accel_data[3], gyro_data[3], temperature;

    /* Call driver init functions */
    GPIO_init();
    Display_init();
    I2C_init();

    // Initialize Display params
    Display_Params uartParams;
    Display_Handle uartHandle;
    Display_Params_init(&uartParams);
    uartHandle = Display_open(Display_Type_UART, &uartParams);

    // I2C CONFIG
    I2C_Params_init(&mpu6050Params);
    mpu6050Params.bitRate = I2C_400kHz;
    mpu6050Params.transferMode = I2C_MODE_BLOCKING;
    mpu6050Handle = I2C_open(CONFIG_I2C_0, &mpu6050Params);

    MPU6050_Reset();

    while (1)
    {
    MPU6050_ReadData(accel_data, gyro_data, &temperature);


    // Display sensor data on UART
    Display_print3(uartHandle, 0, 0, "Accelerometer X_AXIS=%d Y_AXIS=%d Z_AXIS=%d\r\n", accel_data[0], accel_data[1], accel_data[2]);
    Display_print3(uartHandle, 1, 0, "Gyroscope X_AXIS=%d Y_AXIS=%d Z_AXIS=%d\r\n", gyro_data[0], gyro_data[1], gyro_data[2]);
    Display_printf(uartHandle, 2, 0, "Temperature = %.2f °C\r\n", (float)(temperature / 340.0) + 36.53);


    // Sleep for a shorter duration (adjust as needed)
    usleep(100000); // sleep for 100,000 microseconds (0.1 seconds)
    }
    }

    void MPU6050_Reset()
    {
    uint8_t writeData[] = {0x68}; // Send the correct address when sending reset command
    mpu6050Transaction.slaveAddress = MPU6050_ADDRESS;
    mpu6050Transaction.writeBuf = writeData;
    mpu6050Transaction.writeCount = 1;
    I2C_transfer(mpu6050Handle, &mpu6050Transaction);
    }

    void MPU6050_ReadData(int16_t accel_data[3], int16_t gyro_data[3], int16_t *temperature)
    {
    uint8_t writeData;
    uint8_t readData[6];

    // Read Acceleration Data
    writeData = 0x3B; // Wake up the device and send the register address for X axis data
    mpu6050Transaction.slaveAddress = MPU6050_ADDRESS;
    mpu6050Transaction.writeBuf = &writeData;
    mpu6050Transaction.writeCount = 1;
    mpu6050Transaction.readBuf = readData;
    mpu6050Transaction.readCount = 6;
    I2C_transfer(mpu6050Handle, &mpu6050Transaction);

    accel_data[0] = ((readData[0] << 8) | readData[1]); // x-axis data
    accel_data[1] = ((readData[2] << 8) | readData[3]); // y-axis data
    accel_data[2] = ((readData[4] << 8) | readData[5]); // z-axis data

    // Read Gyroscope Data
    writeData = 0x43; // Send the register address for X axis rate divide ratio
    mpu6050Transaction.slaveAddress = MPU6050_ADDRESS;
    mpu6050Transaction.writeBuf = &writeData;
    mpu6050Transaction.writeCount = 1;
    mpu6050Transaction.readBuf = readData;
    mpu6050Transaction.readCount = 6;
    I2C_transfer(mpu6050Handle, &mpu6050Transaction);

    gyro_data[0] = ((readData[0] << 8) | readData[1]); // x-axis data
    gyro_data[1] = ((readData[2] << 8) | readData[3]); // y-axis data
    gyro_data[2] = ((readData[4] << 8) | readData[5]); // z-axis data

    // Read Temperature Data
    writeData = 0x41; // Send the register address for temperature data
    mpu6050Transaction.slaveAddress = MPU6050_ADDRESS;
    mpu6050Transaction.writeBuf = &writeData;
    mpu6050Transaction.writeCount = 1;
    mpu6050Transaction.readBuf = readData;
    mpu6050Transaction.readCount = 2;
    I2C_transfer(mpu6050Handle, &mpu6050Transaction);

    *temperature = ((readData[0] << 8) | readData[1]); // Combine two bytes into a single integer value
    }




    The following is my configuration 

    //// _________________________________________

    I2C on SysConfig

    UART in SysConfig

    Display

  • Hi,

     Have you tried the i2ctmp example I mentioned? Even if you don't have the boosterpack for this example to work, the example will at least print to the terminal. See below line of code that will display the message "Starting the i2ctmp examples"

    Display_printf(display, 0, 0, "Starting the i2ctmp example\n");

  • Yeah, I tried i2ctmp, and both of them worked. Thank you.