I study to read MPU6050 gyro data but the main problem is that I could not achieve. Let me to explain why this problem happen.
I found MPU6050 example for Arduino MPU6050BasicExample.
I have started to change basic Arduino example. Then I applied all codes to my project except of these "writeByte", "readByte", "readBytes" functions.
I have tried to change these code according to Arduino as follow;
These are Arduino codes;
void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
}
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (uint8_t) 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read(); } // Put read results in the Rx buffer
}
These are my codes I have tried to change;
void writeByte(uint16_t address, uint16_t subAddress, uint8_t data)
{
writeI2C0(address, subAddress, data);
}
uint8_t readByte(uint16_t address, uint16_t subAddress)
{
uint8_t data;
return readI2C0(address, subAddress);
}
void readBytes(uint16_t address, uint16_t subAddress, uint8_t count, uint8_t * dest)
{
writeByte(address, subAddress, count);
uint8_t i = 0;
while (I2CMasterBusy(I2C0_BASE)) {
dest[i++] = readByte(address, subAddress); }// Put read results in the Rx buffer
}
In my opinion, if I port Arduino codes to Tiva-c codes, I will achieve to read gyro data.