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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...