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/LAUNCHXL-CC1310: CC1310 && GY521 Gyro Sensor

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

Tool/software: Code Composer Studio

Hi ,

I'm interfacing GY521 with the CC1310LP using I2C(DIO 4&5).

I have imported i2ctmp116 and modified.

Accelerometer and Gyro Sens values are reading zero all the time.

Trying to read Accelerometer(x,y,z) Temperature, Gyro Values(x,y,z) from GY521 but returning values- zero.[I'm able to run the example code i2ctmp116]

Here is my modified code ...

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include <ti/display/Display.h>
#include <xdc/runtime/System.h>

/* Example/Board Header files */
#include "Board.h"

#define TASKSTACKSIZE       640

/* TMP116 DIE Temp Result Register */
//#define TMP116_DIE_TEMP     0x0000
#define GY521_MPU6050     0x0000

/* TMP116 I2C Slave Address */
//#ifdef Board_I2C_TMP116_ADDR
//#define TMP116_ADDR         Board_I2C_TMP116_ADDR
//#else
//#define TMP116_ADDR         0x48
//#endif

//static Display_Handle display;

#ifdef Board_I2C_GY521_ADDR
#define GY521_MPU6050_ADDR         Board_I2C_GY521_MPU6050_ADDR
#else
#define GY521_MPU6050_ADDR         0x68 //0x69 AD=1
#endif

static Display_Handle display;

/*
 *  ======== mainThread ========
 */
char tmp_str[7]; // temporary variable used in convert function

char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
  printf(tmp_str, "%6d", i);
  return tmp_str;
}
void *mainThread(void *arg0)
{
    uint16_t        sample;
    //uint16_t        temperature;
    //uint8_t         txBuffer[1];
    //uint8_t         rxBuffer[2];
      uint16_t        AcX, AcY, AcZ, GyX, GyY, GyZ, TMP;
      float Temperature;
      uint8_t         txBuffer[1];
      uint8_t         rxBuffer[14];
      I2C_Handle      i2c;
      I2C_Params      i2cParams;
      I2C_Transaction i2cTransaction;
      char  x,y,z,X,Y,Z,T;
    /* Call driver init functions */
    Display_init();
    GPIO_init();
    I2C_init();

    /* Configure the LED and if applicable, the TMP116_EN pin
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
#ifdef Board_GPIO_TMP116_EN
    GPIO_setConfig(Board_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
    /* 1.5 ms reset time for the TMP116
    sleep(1);

#endif */


    /* Open the HOST display for output */
    display = Display_open(Display_Type_UART, NULL);
    if (display == NULL) {
        while (1);
    }

    /* Turn on user LED */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
    Display_printf(display, 0, 0, "Starting the i2ctmp116 example\n");

    /* Create I2C for usage */
    I2C_Params_init(&i2cParams);
    i2cParams.bitRate = I2C_400kHz;
    i2c = I2C_open(Board_I2C_TMP, &i2cParams);
    //i2c = I2C_open(Board_I2C_TMP, &i2cParams);
    //i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SDA0, &i2cParams);
    //i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SCL0 , &i2cParams);
    if (i2c == NULL) {
        Display_printf(display, 0, 0, "Error Initializing I2C\n");
        while (1);
    }
    else {
        Display_printf(display, 0, 0, "I2C Initialized!\n");
    }

    /* Point to the die tempature register and read its 2 bytes */
    //txBuffer[0] = TMP116_DIE_TEMP;
    //i2cTransaction.slaveAddress = TMP116_ADDR;
    //i2cTransaction.writeBuf = txBuffer;
    //i2cTransaction.writeCount = 1;
    //i2cTransaction.readBuf = rxBuffer;
    //i2cTransaction.readCount = 2;
      txBuffer[0] = 0x3B;


    i2cTransaction.slaveAddress =  0x68;
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 1;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 14;

    /* Take 20 samples and print them out onto the console */
    for (sample = 0; sample < 20; sample++) {
        if (I2C_transfer(i2c, &i2cTransaction)) {
            /* Extract degrees C from the received data; see TMP116 datasheet */
            //temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
            //temperature *= 0.0078125;
            AcX =   (rxBuffer[0]  <<8) | (rxBuffer[1]);
            AcY =   (rxBuffer[2]  <<8) | (rxBuffer[3]);
            AcZ =   (rxBuffer[4]  <<8) | (rxBuffer[5]);
            TMP =   (rxBuffer[6]  <<8) | (rxBuffer[7]);
            GyX =   (rxBuffer[8]  <<8) | (rxBuffer[9]);
            GyY =   (rxBuffer[10] <<8) | (rxBuffer[11]);
            GyZ =   (rxBuffer[12] <<8) | (rxBuffer[13]);
            //TMP *= 0.0078125;
            Temperature =(TMP/340.00)+36.53;
            Display_printf(display, 0, 0, "Temperature value is : %f \n",Temperature);
            Display_printf(display, 0, 0, "Acx is : %d \n",AcX);

            x   =  convert_int16_to_str(AcX);
            y   =  convert_int16_to_str(AcY);
            z   =  convert_int16_to_str(AcZ);
            X   =  convert_int16_to_str(GyX);
            Y   =  convert_int16_to_str(GyY);
            Z   =  convert_int16_to_str(GyZ);


           //System_printf("Acclerometer Values are %d,%d, %d \n",AcX,AcY,AcZ);

        }

            /*
             * If the MSB is set '1', then we have a 2's complement
             * negative value which needs to be sign extended
             */
           /* if (rxBuffer[0] & 0x80) {
                temperature |= 0xF000;
            }

            Display_printf(display, 0, 0, "Sample %u: %d (C)",
                sample, temperature);
        }
        else {
            Display_printf(display, 0, 0, "I2C Bus fault.");
        }

        /* Sleep for 1 second */
        sleep(1);
    }

    I2C_close(i2c);
    Display_printf(display, 0, 0, "I2C closed!");

    return (NULL);
}

 

  • Hi,

    It looks like your I2C Handle is not initialized correctly. I2C Transaction may also be assigned to 0. Let me know if this helps:

    // Open I2C bus for usage
    I2C_Handle i2cHandle = I2C_open(SENSORS, &params);
    // Initialize slave address of transaction
    I2C_Transaction transaction = {0};
    

    -Simon

  • 
    

    Hi Simon J,

    Thanks for correcting.

    After those changes, it's reading some garbage values from the sensor register. 

    #include <stdint.h>
    #include <stddef.h>
    #include <unistd.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/I2C.h>
    #include <ti/display/Display.h>
    #include <xdc/runtime/System.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    #define TASKSTACKSIZE       640
    
    /* TMP116 DIE Temp Result Register */
    //#define TMP116_DIE_TEMP     0x0000
    #define GY521_MPU6050     0x0000
    
    /* TMP116 I2C Slave Address */
    //#ifdef Board_I2C_TMP116_ADDR
    //#define TMP116_ADDR         Board_I2C_TMP116_ADDR
    //#else
    //#define TMP116_ADDR         0x48
    //#endif
    
    //static Display_Handle display;
    
    #ifdef Board_I2C_GY521_ADDR
    #define GY521_MPU6050_ADDR         Board_I2C_GY521_MPU6050_ADDR
    #else
    #define GY521_MPU6050_ADDR         0x68 //0x69 AD=1
    #endif
    
    static Display_Handle display;
    
    /*
     *  ======== mainThread ========
     */
    char tmp_str[7]; // temporary variable used in convert function
    
    char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
      printf(tmp_str, "%6d", i);
      return tmp_str;
    }
    
    void myCallbackFxn(I2C_Handle handle, I2C_Transaction *msg, bool status)
    {
        if (status == false) {
            //transfer failed
        }
    }
    
    void *mainThread(void *arg0)
    {
        uint16_t        sample;
        //uint16_t        temperature;
        //uint8_t         txBuffer[1];
        //uint8_t         rxBuffer[2];
          uint16_t        AcX, AcY, AcZ, GyX, GyY, GyZ;
          int16_t TMP;
          float Temperature;
          uint8_t         txBuffer[1];
          uint8_t         rxBuffer[14];
          bool status;
          //I2C_Handle i2cHandle = I2C_open(Board_I2C_GY521_MPU6050, &i2cParams);
    
    
          //I2C_Handle      i2c;
          I2C_Params      i2cParams;
          I2C_Params_init(&i2cParams);
          i2cParams.transferMode = I2C_MODE_CALLBACK;
          i2cParams.transferCallbackFxn = myCallbackFxn;
          i2cParams.bitRate = I2C_400kHz;
    
          //I2C_Transaction i2cTransaction;
          I2C_Handle i2c = I2C_open(Board_I2C0, &i2cParams);
          I2C_Transaction i2cTransaction = {0};
          //char  x,y,z,X,Y,Z,T;
        /* Call driver init functions */
        Display_init();
        GPIO_init();
        I2C_init();
    
        /* Configure the LED and if applicable, the TMP116_EN pin
        GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    #ifdef Board_GPIO_TMP116_EN
        GPIO_setConfig(Board_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
        /* 1.5 ms reset time for the TMP116
        sleep(1);
    
    #endif */
    
    
        /* Open the HOST display for output */
        display = Display_open(Display_Type_UART, NULL);
        if (display == NULL) {
            while (1);
        }
    
        /* Turn on user LED */
        GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
        //Display_printf(display, 0, 0, "Starting the i2ctmp116 example\n");
        Display_printf(display, 0, 0, "Starting the GY521 example\n");
    
        /* Create I2C for usage */
        I2C_Params_init(&i2cParams);
        i2cParams.bitRate = I2C_400kHz;
        i2c = I2C_open(Board_I2C_TMP, &i2cParams);
        //i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SDA0, &i2cParams);
        //i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SCL0 , &i2cParams);
        if (i2c == NULL) {
            Display_printf(display, 0, 0, "Error Initializing I2C\n");
            while (1);
        }
        else {
            Display_printf(display, 0, 0, "I2C Initialized!\n");
        }
    
        /* Point to the die tempature register and read its 2 bytes */
        //txBuffer[0] = TMP116_DIE_TEMP;
        //i2cTransaction.slaveAddress = TMP116_ADDR;
        //i2cTransaction.writeBuf = txBuffer;
        //i2cTransaction.writeCount = 1;
        //i2cTransaction.readBuf = rxBuffer;
        //i2cTransaction.readCount = 2;
    
    
    //    txBuffer[0] = 0x3B;
    //    i2cTransaction.slaveAddress =  0x68;
    //    i2cTransaction.writeBuf = txBuffer;
    //    i2cTransaction.writeCount = 1;
    //    i2cTransaction.readBuf = rxBuffer;
    //    i2cTransaction.readCount = 14;
        txBuffer[0] = 0x3B;
        //txBuffer[1] =0x6B;
        i2cTransaction.slaveAddress = 0x68;
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount = 0;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 8;
        status = I2C_transfer(i2c, &i2cTransaction);
        while (status == false) {
            // Unsuccessful I2C transfer
            Display_printf(display, 0, 0, "Unsucessful I2C Read");
            sleep(2);
        }
    
        /* Take 20 samples and print them out onto the console */
        for (sample = 0; sample < 30; sample++) {
            if (I2C_transfer(i2c, &i2cTransaction)) {
                /* Extract degrees C from the received data; see TMP116 datasheet */
                //temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
                //temperature *= 0.0078125;
                AcX =   (rxBuffer[0]  <<8) | (rxBuffer[1]);
                AcY =   (rxBuffer[2]  <<8) | (rxBuffer[3]);
                AcZ =   (rxBuffer[4]  <<8) | (rxBuffer[5]);
                TMP =   (rxBuffer[6]  <<8) | (rxBuffer[7]);
    //            GyX =   (rxBuffer[8]  <<8) | (rxBuffer[9]);
    //            GyY =   (rxBuffer[10] <<8) | (rxBuffer[11]);
    //            GyZ =   (rxBuffer[12] <<8) | (rxBuffer[13]);
                //TMP *= 0.0078125;
                Temperature =TMP/340.00+36.53;
                Display_printf(display, 0, 0, "Temperature value is : %f \n",Temperature);
                Display_printf(display, 0, 0, "AcX is : %d \n",AcX);
                * negative value which needs to be sign extended
                */
              /* if (rxBuffer[0] & 0x80) {
                   temperature |= 0xF000;
               }
    
               Display_printf(display, 0, 0, "Sample %u: %d (C)",
                   sample, temperature);
           }
           else {
               Display_printf(display, 0, 0, "I2C Bus fault.");
           }
    
           /* Sleep for 1 second */
           sleep(3);
       }
    
       I2C_close(i2c);
       Display_printf(display, 0, 0, "I2C closed!");
    
       return (NULL);
    }
           Display_printf(display, 0, 0, "AcY is : %d \n",AcY);
                Display_printf(display, 0, 0, "AcZ is : %d \n",AcZ);
    //            Display_printf(display, 0, 0, "GyX is : %d \n",GyX);
    //            Display_printf(display, 0, 0, "GyY is : %d \n",GyY);
    //            Display_printf(display, 0, 0, "GyZ is : %d \n",GyZ);
    
                //x   =  convert_int16_to_str(AcX);
                //y   =  convert_int16_to_str(AcY);
                //z   =  convert_int16_to_str(AcZ);
                //X   =  convert_int16_to_str(GyX);
                //Y   =  convert_int16_to_str(GyY);
                //Z   =  convert_int16_to_str(GyZ);
    
    
               //System_printf("Acclerometer Values are %d,%d, %d \n",AcX,AcY,AcZ);
    
            }
    
                /*
                 * If the MSB is set '1', then we have a 2's complement
                 * negative value which needs to be sign extended
                 */
               /* if (rxBuffer[0] & 0x80) {
                    temperature |= 0xF000;
                }
    
                Display_printf(display, 0, 0, "Sample %u: %d (C)",
                    sample, temperature);
            }
            else {
                Display_printf(display, 0, 0, "I2C Bus fault.");
            }
    
            /* Sleep for 1 second */
            sleep(3);
        }
    
        I2C_close(i2c);
        Display_printf(display, 0, 0, "I2C closed!");
    
        return (NULL);
    }
    

    I might be doing wrong here am not sure. Since the reading from registers are proper. ( Register Map of MPU 6000 -- www.invensense.com/.../MPU-6000-Register-Map1.pdf

    txBuffer[0] = 0x3B;
        //txBuffer[1] =0x6B;
        i2cTransaction.slaveAddress = 0x68;
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount = 0;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 8;
        status = I2C_transfer(i2c, &i2cTransaction);
        while (status == false) {
            // Unsuccessful I2C transfer
            Display_printf(display, 0, 0, "Unsucessful I2C Read");
            sleep(2);
        }

  • Hi,

    Which pins have you connected your sensor to? How have you mapped whose pins to the Boar_I2C0 in you board file?

    -Simon
  • Hi ,

    I'm using DI04 for the CLK and DIO5 for the DATA from the sensor.

    I have mapped to 

    #define Board_I2C0              CC1310_LAUNCHXL_I2C0    in my Board.h file 

  • Hi,

    Any updates on this?

  • Hi,

    You have set i2cTransaction.writeCount = 0; try to set it to the size of the command you want to send.

    -Simon
  • Hi,

    I don't have to send any command. I just have to start read the Values from the 0x3B register onwards. So have set it to Zero.

    -Lakshminarayana K N.

  • Hi,

    Normally you must send the register address you want to read before you get data from that register. You have set the 0x3B register address in your TX-buffer, but it never gets transmitted since writeCount is set to 0. It must be set to 1.

    -Simon
  • Hi,
    Thanks.
    But when i set the writeCount to 1 it reads Temperature values in negatives(-7C) and Gyro and Acc values never changes.
    When i set the writeCount to 0 it reads the temperature values 36 which is normal.
    I have to start reading from 0x3B Register (0x3B to 0x48 which is set at rxBuffer 14).
    I have referred this example :
    www.mschoeffler.de/.../
    This sensor works fine in Arduino.

    -Lakshminarayana K N.

  • Hi,

    Does your sensor support auto-increments (or burst modes)? If not, you'll need to first write 0x3B -> read the data -> write 0x3C -> read the data etc. to get each register value. This might be implemented in the Arduino function Wire.requestFrom(MPU_ADDR, 7*2, true);

    -Simon
  • Yes Sensor(MPU6050) supports burst mode sensor.
  • Try to change the mode to I2C_MODE_BLOCKING. It may be that you are printing the RX-buffer before it is filled up (I2C transaction is ready)?

    -Simon
  • #include <stdint.h>
    #include <stddef.h>
    #include <unistd.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/I2C.h>
    #include <ti/display/Display.h>
    #include <xdc/runtime/System.h>
    
    /* Example/Board Header files */
    #include "Board.h"
    
    #define TASKSTACKSIZE       640
    
    /* TMP116 DIE Temp Result Register */
    //#define TMP116_DIE_TEMP     0x0000
    #define GY521_MPU6050     0x0000
    
    /* TMP116 I2C Slave Address */
    //#ifdef Board_I2C_TMP116_ADDR
    //#define TMP116_ADDR         Board_I2C_TMP116_ADDR
    //#else
    //#define TMP116_ADDR         0x48
    //#endif
    
    //static Display_Handle display;
    
    #ifdef Board_I2C_GY521_ADDR
    #define GY521_MPU6050_ADDR         Board_I2C_GY521_MPU6050_ADDR
    #else
    #define GY521_MPU6050_ADDR         0x68 //0x69 AD=1
    #endif
    
    static Display_Handle display;
    
    /*
     *  ======== mainThread ========
     */
    char tmp_str[7]; // temporary variable used in convert function
    
    char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
      printf(tmp_str, "%6d", i);
      return tmp_str;
    }
    
    void myCallbackFxn(I2C_Handle handle, I2C_Transaction *msg, bool status)
    {
        if (status == false) {
            //transfer failed
        }
    }
    
    void *mainThread(void *arg0)
    {
        uint16_t        sample;
        //uint16_t        temperature;
        //uint8_t         txBuffer[1];
        //uint8_t         rxBuffer[2];
          uint16_t        AcX, AcY, AcZ, GyX, GyY, GyZ;
          uint8_t         TMPH,TMPL;
          int16_t TMP;
          float Temperature;
          uint8_t         txBuffer[1];
          uint8_t         rxBuffer[14];
          char x;
    
    
    
    
          bool status;
          //I2C_Handle i2cHandle = I2C_open(Board_I2C_GY521_MPU6050, &i2cParams);
    
    
          //I2C_Handle      i2c;
          I2C_Params      i2cParams;
          I2C_Params_init(&i2cParams);
          //i2cParams.transferMode = I2C_MODE_CALLBACK;
          i2cParams.transferMode = I2C_MODE_BLOCKING;
          i2cParams.transferCallbackFxn = myCallbackFxn;
          i2cParams.bitRate = I2C_100kHz;
    
          //I2C_Transaction i2cTransaction;
          //I2C_Handle i2c = I2C_open(Board_I2C0, &i2cParams);
          I2C_Handle i2c = I2C_open( Board_I2C_GY521, &i2cParams);
    
          I2C_Transaction i2cTransaction = {0};
          //char  x,y,z,X,Y,Z,T;
        /* Call driver init functions */
        Display_init();
        GPIO_init();
        I2C_init();
    
        /* Configure the LED and if applicable, the TMP116_EN pin
        GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    #ifdef Board_GPIO_TMP116_EN
        GPIO_setConfig(Board_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
        /* 1.5 ms reset time for the TMP116
        sleep(1);
    
    #endif */
    
    
        /* Open the HOST display for output */
        display = Display_open(Display_Type_UART, NULL);
        if (display == NULL) {
            while (1);
        }
    
        /* Turn on user LED */
        GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
        //Display_printf(display, 0, 0, "Starting the i2ctmp116 example\n");
        Display_printf(display, 0, 0, "Starting the GY521 example\n");
    
        /* Create I2C for usage */
        I2C_Params_init(&i2cParams);
        i2cParams.bitRate = I2C_400kHz;
        //i2c = I2C_open(Board_I2C_TMP, &i2cParams);
        i2c = I2C_open(Board_I2C_GY521, &i2cParams);
        //i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SDA0, &i2cParams);
        //i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SCL0 , &i2cParams);
        if (i2c == NULL) {
            Display_printf(display, 0, 0, "Error Initializing I2C\n");
            while (1);
        }
        else {
            Display_printf(display, 0, 0, "I2C Initialized!\n");
        }
    
        /* Point to the die tempature register and read its 2 bytes */
        //txBuffer[0] = TMP116_DIE_TEMP;
        //i2cTransaction.slaveAddress = TMP116_ADDR;
        //i2cTransaction.writeBuf = txBuffer;
        //i2cTransaction.writeCount = 1;
        //i2cTransaction.readBuf = rxBuffer;
        //i2cTransaction.readCount = 2;
    
    
    //    txBuffer[0] = 0x3B;
    //    i2cTransaction.slaveAddress =  0x68;
    //    i2cTransaction.writeBuf = txBuffer;
    //    i2cTransaction.writeCount = 1;
    //    i2cTransaction.readBuf = rxBuffer;
    //    i2cTransaction.readCount = 14;
        //txBuffer[1] = 0x6B;
        //txBuffer[2] = 0x00;
        txBuffer[1] = 0x3B;
    
        i2cTransaction.slaveAddress = 0x68;
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount =1;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 14;
        status = I2C_transfer(i2c, &i2cTransaction);
        while (status == false) {
            // Unsuccessful I2C transfer
            Display_printf(display, 0, 0, "Unsucessful I2C Read");
            sleep(2);
        }
    
        /* Take 20 samples and print them out onto the console */
        for (sample = 0; sample < 5; sample++) {
            if (I2C_transfer(i2c, &i2cTransaction)) {
                /* Extract degrees C from the received data; see TMP116 datasheet */
                //temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
                //temperature *= 0.0078125;
                AcX =   (rxBuffer[0]  <<8) | (rxBuffer[1]);
                AcY =   (rxBuffer[2]  <<8) | (rxBuffer[3]);
                AcZ =   (rxBuffer[4]  <<8) | (rxBuffer[5]);
                TMP =   (rxBuffer[6]  <<8) | (rxBuffer[7]);
                GyX =   (rxBuffer[8]  <<8) | (rxBuffer[9]);
                GyY =   (rxBuffer[10] <<8) | (rxBuffer[11]);
                GyZ =   (rxBuffer[12] <<8) | (rxBuffer[13]);
                TMPH= rxBuffer[6];
                TMPL= rxBuffer[7];
                //TMP *= 0.0078125;
                Temperature =TMP/340.00+36.53;
                Display_printf(display, 0, 0, "Temperature value is : %f \n",Temperature);
                Display_printf(display, 0, 0, "AcX is : %d \n",AcX);
                Display_printf(display, 0, 0, "AcY is : %d \n",AcY);
                Display_printf(display, 0, 0, "AcZ is : %d \n",AcZ);
                Display_printf(display, 0, 0, "GyX is : %d \n",GyX);
                Display_printf(display, 0, 0, "GyY is : %d \n",GyY);
                Display_printf(display, 0, 0, "GyZ is : %d \n",GyZ);
                Display_printf(display, 0, 0, "TMPH is  %d \n",TMPH);
                Display_printf(display, 0, 0, "TMPL is  %d \n",TMPL);
    
                x   =  convert_int16_to_str(AcX);
                //Display_printf(display,0,0,"Accelerometer is %c \n",x);
                //y   =  convert_int16_to_str(AcY);
                //z   =  convert_int16_to_str(AcZ);
                //X   =  convert_int16_to_str(GyX);
                //Y   =  convert_int16_to_str(GyY);
                //Z   =  convert_int16_to_str(GyZ);
                }
    
                /*
                 * If the MSB is set '1', then we have a 2's complement
                 * negative value which needs to be sign extended
                 */
               /* if (rxBuffer[0] & 0x80) {
                    temperature |= 0xF000;
                }
    
                Display_printf(display, 0, 0, "Sample %u: %d (C)",
                    sample, temperature);
            }
            else {
                Display_printf(display, 0, 0, "I2C Bus fault.");
            }
    
            /* Sleep for 1 second */
    
            sleep(3);
        }
    
        I2C_close(i2c);
        Display_printf(display, 0, 0, "I2C closed!");
    
        return (NULL);
    }

    And it returns this :

  • Hi,

    Still no luck.

    -Lakshminarayana K N
  • txBuffer[1] = 0x3B; should be txBuffer[0] = 0x3B; otherwise you will start reading from whatever is stored in txBuffer[0].

    -Simon
  • With those changes as txBuffer[0] = 0x3B;
    I'm able to read constant Temperature of(35C) and even the accelerometer values varies when sensor moved.
    but Gyro values returning zero.
    -Lakshminarayana K N.