5 Replies Latest reply on Feb 20, 2018 7:18 AM by e.pratt_1639216

    error in I2C communication between PSOC BLE-4 and MPU-6050

    fa235_1780096

      I am trying to use one of the codes taken from PSOC community (MPU 6050 - Need help reading sensor values), and made the changes as recommended by latest API as suggested by the community. When I run it, it says that MPU6050 failed to connect. I wonder if someone pro at i2c and psoc could help me resolve that issue. I am attaching my project here.

       

      Thanks in advance:

       

      Apoorva

        • 1. Re: error in I2C communication between PSOC BLE-4 and MPU-6050
          bob.marlowe

          Every I2C API returns a status which you can analyze. Values returned != 0 indicate an error, description found in the appropriate .h file.

          Some .h files are missing, so it is difficult to have the compiler find declarations and definitions.

           

          Bob

          • 2. Re: error in I2C communication between PSOC BLE-4 and MPU-6050
            fa235_1780096

            Bob,

             

            Thanks for replying.

            The MPU6050 library is included in the project-- so i am not sure which .h files are missing. The code compiles, and prints numbers on the UART. Just that readings are not available the MPU6050.

             

            On the page from where I downloaded the file, you had replied that i2c API changed. Sebastian later modified that part with the following piece of the code:

             

            =============================old code===========================================

            void I2CReadBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *value) {

                 uint8_t i=0;

                 I2C_MPU6050_I2CMasterSendStart(devAddr, I2C_MPU6050_I2C_WRITE_XFER_MODE);

                 I2C_MPU6050_I2CMasterWriteByte(regAddr);

                 I2C_MPU6050_I2CMasterSendRestart(devAddr, I2C_MPU6050_I2C_READ_XFER_MODE);

                 while (i++ < (length-1)) {

                      *value++ = I2C_MPU6050_I2CMasterReadByte(I2C_MPU6050_I2C_ACK_DATA);

                 }

                 *value = I2C_MPU6050_I2CMasterReadByte(I2C_MPU6050_I2C_NAK_DATA);

                 I2C_MPU6050_I2CMasterSendStop();

            }

             

            =============================new code===========================================

            void I2CReadBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *value) {

            uint8_t i=0;

            I2C_MPU6050_I2CMasterSendStart(devAddr, I2C_MPU6050_I2C_WRITE_XFER_MODE,0);

            I2C_MPU6050_I2CMasterWriteByte(regAddr,0);

            I2C_MPU6050_I2CMasterSendRestart(devAddr, I2C_MPU6050_I2C_READ_XFER_MODE,0);

            while (i++ < (length-1)) {

                I2C_MPU6050_I2CMasterReadByte(I2C_MPU6050_I2C_ACK_DATA,value++,0);

            }

            I2C_MPU6050_I2CMasterReadByte(I2C_MPU6050_I2C_NAK_DATA,value,0);

            I2C_MPU6050_I2CMasterSendStop(0);

            }

             

            ===============================================================================

             

            I am afraid that this the part of the code that is affecting the reading part. Could you please help me?

             

            Best,

            Apoorva

            • 3. Re: error in I2C communication between PSOC BLE-4 and MPU-6050
              hima

              Hello,

               

              Kindly test this particular code from a third party blog.

               

              Sam's Blog : Getting Roll, Pitch and Yaw from MPU-6050

               

              This would work only with old version of Creator. First try if the project is working fine in the older version of Creator so that we can confirm its not a hardware issue.

               

              Thanks,

              Hima

              1 of 1 people found this helpful
              • 4. Re: error in I2C communication between PSOC BLE-4 and MPU-6050
                fa235_1780096

                Thanks, Hima. Actually, this is the old code, and i2c protocol has changed since then. PSOC4.1 throws error while compiling this code. 

                 

                I found the reason for the error. The pull-up resistance between SCL and SDA wasn't connected properly, which was communication was stuck.

                 

                Best,

                Apoorva

                • 5. Re: error in I2C communication between PSOC BLE-4 and MPU-6050
                  e.pratt_1639216

                  Simple solution XD

                  It's hard to find bugs and issues sometimes...