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

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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

0 Likes
1 Solution
Anonymous
Not applicable

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

View solution in original post

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

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

0 Likes
Anonymous
Not applicable

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

0 Likes
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

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

Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

Simple solution XD

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

0 Likes