I2C write problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi

I am trying to interface InvenSense MPU9150 motion detector sensor with Tag3 board. I found difficulty when i tried to write 0 on one of register of sensor in order to start sensor. I am very new in I2C programming. I posted function below kindly look into this. Thanks

UINT8 sensor_app_writeSensor(UINT8 register_address, UINT8 data)

{

    UINT8 read_status;

    UINT8 return_value = 0;

    UINT8 reg_data_bytes[2];

    reg_data_bytes[0]= register_address;

    reg_data_bytes[1] = data;

    read_status = i2cm_write(reg_data_bytes, sizeof(reg_data_bytes), MPU9150_I2C_ADDRESS);

    ble_trace1("read status=%d\n",MPU9150_PWR_MGMT_1);

    switch(read_status)

    {

        case I2CM_BUSY:

            // Transaction did not go through. ERROR. Handle this case.

        ble_trace0("\ndone4.\n");

            break;

        case I2CM_SUCCESS:

            // The read was successful.

        ble_trace0("\ndone5.\n");

            return_value = 1;

            break;

        case I2CM_OP_FAILED:

            // No slave device with this address exists on the I2C bus. ERROR. Handle this.

        ble_trace0("\ndone6.\n");

        default:

            break;

    }

    return return_value;

}

void  motion_sensor_read_and_print_motion_data(void)

{    UINT8 return_value = 0;

     INT8 motion_data;

     INT16 gcd;

     i2cm_init();

          /* the default speed is 100kHz, it's not required the speed config. */

          i2cm_setSpeed(I2CM_SPEED_400KHZ);

          i2cm_setTransactionSpeed();

              

          sensor_app_writeSensor(MPU9150_PWR_MGMT_1, 0);

          ble_trace0("\nStarting new measurement.\n");

   

    motion_data=sensor_app_readSensor(MPU9150_ACCEL_XOUT_L,MPU9150_ACCEL_XOUT_H);

         ble_trace1("motion_sensor_read_motion_data returned %d\n",motion_data);

   

}

0 Likes
1 Solution
Anonymous
Not applicable

Now I2C is working i just did shifting on my I2C address and it start working.

int MPU9150_I2C_ADDRESS = (0x68<< 1) ;

Thanks for help and support.

View solution in original post

0 Likes
16 Replies