Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > I2C communication with MPU-6050 fails?

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



I2C communication with MPU-6050 fails?
Moderator:
ANCY

Post Reply
Follow this topic



I2C communication with MPU-6050 fails?

Texton posted on 27 Sep 2012 11:00 AM PST
Member
10 Forum Posts

 Hi all. 

I got at big problem regarding I2C communication with the MPU6050. 

I seem to have tried everything but it just wont work. The protocol can be found at: 

http://invensense.com/mems/gyro/documents/PS-MPU-6000A.pdf  (page 37)

The problem is that  I2C_1_MasterSendStart(devAddr, I2C_1_WRITE_XFER_MODE) returns I2C_MSTR_ERR_LB_NAK ??? Which I dont understand. 

Here's my souce code: 

void main(){

    uint8 wrData;
    uint8 rdData;
    uint8 status; 
    uint8 readFlag;
    uint8 breakp; 
    uint8 masterStatus; 

    I2C_1_Start();

    wrData = 117;   //Reg number
    uint8 devAddr = 0b110100;

    for(;;){

        status = I2C_1_MasterSendStart(devAddr, I2C_1_WRITE_XFER_MODE); 

        if(status == I2C_1_MSTR_NO_ERROR){         /* Check if transfer completed without errors */

            status = I2C_1_MasterWriteByte(wrData);   
       }

       I2C_1_MasterSendStop();    /* Send Stop */

      status = I2C_1_MasterSendStart(devAddr, I2C_1_READ_XFER_MODE);

       if(status == I2C_1_MSTR_NO_ERROR) {         /* Check if transfer completed without errors */

  rdData = I2C_1_MasterReadByte(I2C_1_NAK_DATA);

    }

        

    I2C_1_MasterSendStop(); /* Send Stop */

    }

}

 

Now problem is the if's are always going false because of the status :( .. 

Any help pls?




Re: I2C communication with MPU-6050 fails?

H L posted on 27 Sep 2012 08:26 PM PST
Top Contributor
679 Forum Posts

1.Try using I2C_MasterClearStatus() frist before the write/read

2. It would be helpful if you can post the project up here.



Re: I2C communication with MPU-6050 fails?

Bob Marlowe posted on 28 Sep 2012 11:38 PM PST
Top Contributor
1768 Forum Posts

You are still using the wrong address, it must be 0x68.

 

Bob



Re: I2C communication with MPU-6050 fails?

Bob Marlowe posted on 28 Sep 2012 11:45 PM PST
Top Contributor
1768 Forum Posts

Sorry, too fast.

You are defining a 6-bit binary value and rely on the compiler that it will insert it into the "right" places. If this would work right now this is hazardous when the compiler got changed / updated.

The Datasheet tells to take the given bit-pattern and to append 1 bit from the hard-wired A0 input, so we have got 7 bits already and that is our complete slave address, the rest is handled by I2C. so we come to 0b01101000 which is 0x64 if I am not mistaken.

 

Bob



Re: I2C communication with MPU-6050 fails?

hli posted on 28 Sep 2012 01:07 AM PST
Top Contributor
675 Forum Posts

The I2C address seems to be wrong. You define it as 0b110100, but according to the data sheet it should be 0b1101000 (watch for the additional zero).



Re: I2C communication with MPU-6050 fails?

hli posted on 28 Sep 2012 01:08 AM PST
Top Contributor
675 Forum Posts

Oh - Bob was too fast and I was too slow :(



Re: I2C communication with MPU-6050 fails?

Bob Marlowe posted on 28 Sep 2012 01:40 AM PST
Top Contributor
1768 Forum Posts

Do not be dissapointed, you were right too :-)

 

Bob



Re: I2C communication with MPU-6050 fails?

Bob Marlowe posted on 28 Sep 2012 01:42 AM PST
Top Contributor
1768 Forum Posts

Ahh and by the way, I WAS mistaken, it is 0x68 of course!



Re: I2C communication with MPU-6050 fails?

hli posted on 28 Sep 2012 03:58 AM PST
Top Contributor
675 Forum Posts

Math is hard, and binary math double so



Re: I2C communication with MPU-6050 fails?

Bob Marlowe posted on 28 Sep 2012 11:50 AM PST
Top Contributor
1768 Forum Posts

Yes, there are 10 different kinds of people, those who understand binary and those who don't.

 

Bob



Re: I2C communication with MPU-6050 fails?

hli posted on 28 Sep 2012 01:39 PM PST
Top Contributor
675 Forum Posts

To be more OnT: There are two types of people in the world: 1. Those who can extrapolate from incomplete data.



Re: I2C communication with MPU-6050 fails?

hli posted on 28 Sep 2012 01:39 PM PST
Top Contributor
675 Forum Posts

@Texton: can you tell us whether this was the problem or not?






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20