I2C with MPU5060

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

cross mob
alma_284856
Level 3
Level 3
First like received

 Hi everyone,

   

I try to use a sensor MPU5060 in I2C but I get some trouble.

   

In my memories it easy to use I2C with PsoC but It doesn't work 😞

   

My device adresse is 0x68;
I define  uint8 test=0x43; which is the adresse of MPU6050_GYRO_XOUT_H_REG 
and     uint8 userArray[10]={0,0,0,0,0,0,0,0,0,0};

   
        
   

After designed the .CYSCH I write on my code:

   

I2C_1_Start();

   

while(1){

   

I2C_1_MasterClearStatus(); 

   

2C_1_MasterWriteBuf(MPU6050_ADDRESS , &test, 1, I2C_1_MODE_COMPLETE_XFER );

   

while (I2C_1_MasterStatus() & I2C_1_MSTAT_XFER_INP);

   

CyDelay(10);

   

I2C_1_MasterClearStatus(); 

   

I2C_1_MasterReadBuf(MPU6050_ADDRESS  , userArray, 1,I2C_1_MODE_COMPLETE_XFER );

   

while (I2C_1_MasterStatus() & I2C_1_MSTAT_XFER_INP);

   

CyDelay(10);

   

val = ((int)userArray[0])*256 + (int)userArray[1];

   

sprintf(buf, "userArray\t%d\t%d\t%d\t%d\n\r",(int)userArray[0],(int)userArray[1], val, (int)test) ;

   
    UART_1_PutString(buf);   
   

}

But It returns nothing 😞

   

 

   

Thank you

0 Likes
5 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

1) This line of code 2C_1_MasterWriteBuf(MPU6050_ADDRESS , &test, 1, I2C_1_MODE_COMPLETE_XFER ); is missing

   

the "I" at beggining of line, eg. should be I2C_.......

   

 

   

2) Pull ups installed on SDFA and SCL ?

   

 

   

3) On scope levels and timing look right for speed ?

   

 

   

4) userArray is long enough + 1 for the null character to terminate string ?

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

This 2) Pull ups installed on SDFA and SCL ? should read this 2) Pull ups installed on SDA and SCL ?

0 Likes
alma_284856
Level 3
Level 3
First like received

 Yep sorry I forgot teh "I" when I copied/pasted my code...

   

There are already resistor on the board of the mpu5060

   

and for the speed I choose 100K like the datasheet... :'(

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

For most I2C-devices the first write to specify which register to read from has to be made with No_Stop and the reading with Repeat_start. I personally prefer the more basic functions SendStart(), WriteByte(), SendRestart(), ReadByte and SendStop() in that order.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You have seen this site, it has code possibly you could port -

   


   

     

   

            http://www.i2cdevlib.com/devices/mpu6050#source

   


   

Regards, Dana.

0 Likes