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/CC1350STK: accelerometer, gyroscope (x,y,z axis) values doesn't change

Part Number: CC1350STK

Tool/software: Code Composer Studio

Hi

I am getting same accelerometer and gyroscope values for all axis.The value i am getting is 19456 for x,y,z axis for both sensors.

For gyroscope i am using this code

txBuffer[0] = 0x43;
txBuffer[1] = 0x44 ;
txBuffer[2] = 0x45;
txBuffer[3] = 0x46;
txBuffer[4] = 0x47;
txBuffer[5] = 0x48;
i2cTransaction.slaveAddress = Board_MPU9250_ADDR;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 6;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 6;

for (i = 0; i < 20; i++) {
if (I2C_transfer(i2c, &i2cTransaction)) {

gyroX = (((int16_t)rxBuffer[1]) << 8) | rxBuffer[0];
gyroY = (((int16_t)rxBuffer[3]) << 8) | rxBuffer[2];
gyroZ = (((int16_t)rxBuffer[5]) << 8) | rxBuffer[4];
int16_t gyrox = SensorMpu9250_gyroConvert(gyroX);
int16_t gyroy = SensorMpu9250_gyroConvert(gyroY);
int16_t gyroz = SensorMpu9250_gyroConvert(gyroZ);          //Function call to source code file

.............

and for accelerometer 

txBuffer[0] = 0x3B;
txBuffer[1] = 0x3C;
txBuffer[1] = 0x3D;
txBuffer[3] = 0x3E;
txBuffer[3] = 0x3F;
txBuffer[5] = 0x40;
i2cTransaction.slaveAddress = Board_MPU9250_ADDR; 
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 3;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 3;

/* Take 20 samples and print them out onto the console */
for (i = 0; i < 20; i++) {
if (I2C_transfer(i2c, &i2cTransaction)) {
accelerationX = (((int16_t)rxBuffer[1]) << 8) | rxBuffer[0];
accelerationY = (((int16_t)rxBuffer[3]) << 8) | rxBuffer[2];
accelerationZ = (((int16_t)rxBuffer[5]) << 8) | rxBuffer[4];
int16_t accelx = SensorMpu9250_accConvert(accelerationX);
int16_t accely = SensorMpu9250_accConvert(accelerationY);
int16_t accelz = SensorMpu9250_accConvert(accelerationZ);

is there anything i am doing wrong?any help would be greatly appreciated

thanks in advance

best regards

Shyam

  • Please take a look at the code examples for the different sensors referred to here:
    processors.wiki.ti.com/.../CC2650_SensorTag_User's_Guide

    BR
    Siri
  • Hi Siri
    Thanks for the reply and the link.I have gone through the link but that did not solve my issue.
    also read the datasheets of the invensense but dono where i am going wrong..i need help to solve this issue
    I am using this command to enable Gyro sensor
    SensorMpu9250_enable(0x012); // 0 for z axis, 1 for y axis, 2 for x axis Gyroscope
    is this the proper way to enable sensor?
    Before enabling the sensor i am turing the Sensormpu9250 power on and initialising it.
    i feel rest of the program which is in previous post is okay.

    Thanks in advance,
    kind regards
    Shyam
  • I am not an expert on the Mpu9250 but I found some code snippets on the forum and put together a small example. Hopefully that will help you:

    #include <ti/mw/sensors/SensorI2C.h>
    #include <ti/mw/sensors/SensorMpu9250.h>
    
    static  float acc_x;
    static  float acc_y;
    static  float acc_z;
    static  float gyro_x;
    static  float gyro_y;
    static  float gyro_z;
    
    void *mainThread(void *arg0)
    {    
        if (SensorI2C_open())
        {
            SensorMpu9250_init();
            SensorMpu9250_powerOn();
            SensorMpu9250_enable(0x003F);
        }
        
        while(1)
        {
            bool success;
            uint16_t accData[3];
            uint16_t gyroData[3];
    
            // Read the data
            success = SensorMpu9250_accRead(accData);
            if (success)
            {
                acc_x = SensorMpu9250_accConvert(accData[0]);
                acc_y = SensorMpu9250_accConvert(accData[1]);
                acc_z = SensorMpu9250_accConvert(accData[2]);
            }
            
            success = SensorMpu9250_gyroRead(gyroData);
            if (success)
            {
                gyro_x = SensorMpu9250_gyroConvert(gyroData[0]);
                gyro_y = SensorMpu9250_gyroConvert(gyroData[1]);
                gyro_z = SensorMpu9250_gyroConvert(gyroData[2]);
            }
        }
    }
    

    BR

    Siri

  • HI Siri
    Many thanks for your reply and sorry to bother you again.Code you have provided also gets zero from all axis.
    I have tried code like this
    success = SensorMpu9250_accRead(accData); //please let me know if my understanding is right.accData is the result address which has all datas.if so i am not able to find this result register in mpu9250 datasheet.In datasheet i could find that there are 2 registers i.e for msb and lsb.So i have tried also with ACCEL_XOUT_H instead of accData
    if (success)
    {
    txBuffer[0] = ACCEL_XOUT_H; //0x3B
    txBuffer[1] = ACCEL_XOUT_L; //0x3C
    txBuffer[2] = ACCEL_YOUT_H; //0x3D
    txBuffer[3] = ACCEL_YOUT_L; //0x3E
    txBuffer[4] = ACCEL_ZOUT_H; //0x3F
    txBuffer[5] = ACCEL_ZOUT_L; //0x40
    i2cTransaction.slaveAddress = Board_MPU9250_ADDR; // 0x68
    i2cTransaction.writeBuf = txBuffer;
    i2cTransaction.writeCount = 6;
    i2cTransaction.readBuf = rxBuffer;
    i2cTransaction.readCount = 6;
    accData[0]= ((int16_t)rxBuffer[1] << 8) | rxBuffer[0];
    accData[1]= (((int16_t)rxBuffer[3]) << 8) | rxBuffer[2];
    accData[2]= (((int16_t)rxBuffer[5]) << 8) | rxBuffer[4];
    acc_x = SensorMpu9250_accConvert(accData[0]);
    acc_y = SensorMpu9250_accConvert(accData[1]);
    acc_z = SensorMpu9250_accConvert(accData[2]);
    }
    but still it reads zero for x,y,z axis .Again for gyro with similar approach results zero for x,y,z axis.
    In SensorTag android application the values are changing btn.
    what could be the possible solution for this?
    Thanks in advance
    Regards
    Shyam
  • Please take and test my code as I have posted it without any modifications. You can do this my using the rfPacketTx example for the CC1350STK from the simplelink_cc13x0_sdk_1_60_00_21 and replace the rfPacketTx.c file with the one I have attached.

    rfPacketTx.c
    /*
     * Copyright (c) 2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /***** Includes *****/
    /* Standard C Libraries */
    #include <stdlib.h>
    
    /* TI Drivers */
    #include <ti/drivers/rf/RF.h>
    #include <ti/drivers/PIN.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    
    
    #include <ti/mw/sensors/SensorI2C.h>
    #include <ti/mw/sensors/SensorMpu9250.h>
    
    
    /* Driverlib Header files */
    #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h)
    
    /* Board Header files */
    #include "Board.h"
    #include "smartrf_settings/smartrf_settings.h"
    
    /*
     * Application LED pin configuration table:
     *   - All LEDs board LEDs are off.
     */
    PIN_Config pinTable[] =
    {
        Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PIN_TERMINATE
    };
    
    static  float acc_x;
    static  float acc_y;
    static  float acc_z;
    static  float gyro_x;
    static  float gyro_y;
    static  float gyro_z;
    
    
    /***** Function definitions *****/
    
    void *mainThread(void *arg0)
    {    
        if (SensorI2C_open())
        {
            SensorMpu9250_init();
            SensorMpu9250_powerOn();
            SensorMpu9250_enable(0x003F);
        }
        
        while(1)
        {
            bool success;
            uint16_t accData[3];
            uint16_t gyroData[3];
    
            // Read the data
            success = SensorMpu9250_accRead(accData);
            if (success)
            {
                acc_x = SensorMpu9250_accConvert(accData[0]);
                acc_y = SensorMpu9250_accConvert(accData[1]);
                acc_z = SensorMpu9250_accConvert(accData[2]);
            }
            
            success = SensorMpu9250_gyroRead(gyroData);
            if (success)
            {
                gyro_x = SensorMpu9250_gyroConvert(gyroData[0]);
                gyro_y = SensorMpu9250_gyroConvert(gyroData[1]);
                gyro_z = SensorMpu9250_gyroConvert(gyroData[2]);
            }
        }
    }
    
    

    Siri