cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

Hello,

For a project I need to read out the sensor values of the MPU 6050.

After doing some research I downloaded the project in this topic from 3 months ago MPU6050 w/PSOC4 - Implementing a Filter

The only problem I am facing is that I am getting errors that there are too few arguments in the I2C functions provided by PSoC after I build the project.

For example code for reading a byte of data:

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();

}

These functions expect more parameters now than the project that I downloaded from 3 months ago, while the project is still PSoC 4.

Is it possible to avoid these errors so I can use this project to read the data?

Thanks for reading

Sebastiaan

0 Likes
Reply
1 Solution
Anonymous
Not applicable

Incase anyone needs the fixed function:

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);

}

View solution in original post

0 Likes
Reply
3 Replies
JoMe_264151
Expert II

The I2C component has been modified and now implements a timeout parameter. When set to 0 (zero) it acts as before.

The I2C_ReadByte() API was changed to return a status and has one param more for the address of the data to return.

Right click on the component to get access to the datasheet and the description of the APIs.

Bob

0 Likes
Reply
Anonymous
Not applicable

Incase anyone needs the fixed function:

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);

}

View solution in original post

0 Likes
Reply
Anonymous
Not applicable

Hi Sebastian,

I am trying to use your code, and made the changes you recommended in I2CReadBytes(...) function. When I run it, it says that MPU6050 failed to connect. I wonder if you could help me resolve that issue. I am attaching my project here.

It would be very helpful if you could share your latest working project with me.

Best,

Apoorva

0 Likes
Reply