Jump to content
Sign in to follow this  
ryseek

Msp430g2231 i2c mpu6050 issue

Recommended Posts

Hi everyone!
I need to connect mpu6050 to msp430g2231 and i've read article http://www.kerrywong...aster-examples/

My code : 

#include <msp430.h>
#include <msp430g2231.h>
#include "i2c.h"
int AcX,AcY,AcZ;
unsigned char i2cAddress = 0x68;
int accel;
int count;
unsigned char high;
unsigned char low;


void initMPU()
{

  i2c_start();//
  i2c_write8(i2cAddress << 1);/// begin tarmition
  i2c_write8(0x68);
  i2c_write8(0);
  i2c_stop();
}

void main(void) {
    WDTCTL = WDTPW + WDTHOLD;

    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;

    i2c_init();

    initMPU();

    while(1){


    	 i2c_start();//
      i2c_write8(i2cAddress << 1);/// begin tarmiti
      i2c_write8(0x3B);
      i2c_stop();

      i2c_start();
      i2c_write8(i2cAddress<< 1 | 1);
      AcX=i2c_read8(0x0)<<8|i2c_read8(0x0);

      i2c_stop();

    }
}

The debugger show the value of AcX=-1, sometimes=-4,but very rare real values of axis. 


Need help!  :unsure:

Share this post


Link to post
Share on other sites

@@ryseek

 

I have never worked with the mpu6050 but the code looks sane.

 

Bust out your logic analyer and watch the clock and data lines during a transaction.

 

What do you see?

Share this post


Link to post
Share on other sites

Also, check to make sure that your hardware is connected properly.  Although, you probably did that already. ;-)

 

Note, if you are working with a LaunchPad board, you have to remove the jumper on P1.6 to get I2C mode working.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×