|
Thanks Bob for the support,
After alot of trying (and failing) the following code works:
int32 i;
uint8 wrData[1], rdData[2]; // Put in the wrData[0] array the register address
volatile uint8 status;
I2C_Start();
status = I2C_MasterSendStart(MPU6050_ADD, I2C_WRITE_XFER_MODE);
if(status == I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */
{
/* Send array of 1 bytes */
for(i=0; i<1; i++)
{
status = I2C_MasterWriteByte(wrData[i]);
if(status != I2C_MSTR_NO_ERROR) break;
}
}
I2C_MasterSendStop(); /* Send Stop */
status = I2C_MasterSendStart(MPU6050_ADD, I2C_READ_XFER_MODE);
if(status == I2C_MSTR_NO_ERROR) /* Check if transfer completed without errors */
{
/* Read array of 2 bytes */
for(i=0; i<2; i++)
{
if(i < 1) rdData[i] = I2C_MasterReadByte(I2C_ACK_DATA);
else rdData[i] = I2C_MasterReadByte(I2C_NAK_DATA);
}
}
I2C_MasterSendStop(); /* Send Stop */
I2C_Stop();
|