Output shoes constant values from MPU-6050 on Atmega8 via I2C?

Discussion in 'Embedded Systems and Microcontrollers' started by MARKaka65, May 28, 2014.

  1. MARKaka65

    Thread Starter New Member

    May 28, 2014
    5
    2
    Hi All!

    I am trying to connect an MPU-6050 (ITG-MPU breakout board) with ATmega8 (on a breadboard - non arduino) via I2C.

    When I try to read one of the sensor values the TWSR values show perfect I2C communication,
    like for example twsr values for: Start, Slave+W, Address ack, Register AddressACK, Slave+R, Data to twdr, nack by master, Stop, etc. all match with atmega8's data-sheet (I connected 8-pins of portD to 8 LEDS and set twsr to display on this port every time a twsr check operation is performed).

    But the values I receive in twdr are all constant and does not change by any movements of sensor (I tried displaying the sensed values on an 8-LEDS arrangement and also on an lcd).

    I communicate on i2c in following manner:
    Send Start,
    Check twsr,
    Send Slave address with write bit,
    Wait for NACK or ACK,
    Check TWSR,
    Send Sensor register address,
    Wait for NACK or ACK,
    Check TWSR,
    Send START (repeated start)
    Check TWSR,
    Send Slave address with read,
    Wait for NACK or ACK,
    Check TWSR,
    Copy TWDR data to an element of an Array,
    Send "NACK",
    Check TWSR
    Stop.

    I continuously monitor TWINT flag in all steps. And these steps are repeated again and again for different sensor registers.
    Also I have enabled interrupt (by including sei ) but I have not put anything in the Interrupt vector.

    My Question(s) is :

    Why is this data constant?

    Is there a problem with my I2C communication approach?

    Or is the MPU operating on 3V3 and AVR on 5V killing the sensed data? (I use 4K7 pull-ups to 5V)

    Or any other registers are to be configured (I tried PWR_MGMT_1, USER_CTRL, CONFIG, SMPRT_DIV, GYRO_CONFIG, ACCEL_CONFIG in this very order) before actual register addressing and data reading?

    Or some other problem?

    If similar experience had been discussed before or a discussion that might help, Please redirect.

    Thanks.

    Pardon my typing.
     
    Last edited: May 28, 2014
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    If you see ACK from the slave you are talking to it. It may need further set up or register selection to get to the real data.

    I can't figure out what device you are talking to to peek at the data sheet. A link would help.
     
  3. MARKaka65

    Thread Starter New Member

    May 28, 2014
    5
    2
  4. MARKaka65

    Thread Starter New Member

    May 28, 2014
    5
    2
    I use following approach to make a sensor word from two sensor register :

    Code ( (Unknown Language)):
    1.  
    2. unsigned char RCVD_L, RCVD_H;    // these store lower and higher 8-bits of sensor data from the two sensor registers meant for one sensor value respectively
    3. int INTRMDT, HSB, LSB, GYRO_Z;
    4.  
    5.  
    6. LSB = RCVD_L;
    7. HSB = RCVD_H;
    8. INTRMDT = ((HSB << 8) | LSB);
    9. GYRO_Z = INTRMDT;
    10.  
     
  5. MARKaka65

    Thread Starter New Member

    May 28, 2014
    5
    2
    I figured one thing that if I Copy TWDR data to an element of an Array after sending NACK to stop communication I get changing values and output values are no more constant.

    Thank you @ErnieM for making me think in that way.
     
    ErnieM likes this.
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    What I say? Wha I say?

    Sorry I missed your clarity post. My "guess" is some slaves need the master to send a NAK when done getting data so they reset for the next group.

    Anyway, I'm glad you made progress. (Now to check if the changing data is actually valid data.)
     
  7. MARKaka65

    Thread Starter New Member

    May 28, 2014
    5
    2
    Ya ErnieM it is found out to be the valid data, and in later phase of development I used that data to perform my requisite function. This error was the bottleneck of my project and once it was rectified, complete setup started working like it should be within a fractional percentage of complete development time. Now I am on to my next project. Will trouble u if I get stuck again. :D :D
     
    ErnieM likes this.
Loading...