0

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.

Yılmaz edis
  • 146
  • 3
  • 13
  • What was the question? What have you tried yourself to answer it? – domen Oct 31 '18 at 13:20
  • Sorry for my bad explanation. I want to change arduino "writeByte", "readByte", "readBytes" functions according to Tiva-c for code composer. I mean, I want to port arduino wire library to code composer. Do you think that makes sense. İt is my graduate project to finish my school. I got stuck reading the mpu6050 – Yılmaz edis Oct 31 '18 at 20:18
  • What do you expect anyone to do with the info you have provided? Does reading this https://stackoverflow.com/help/how-to-ask help you understand how to ask a better question? – domen Nov 01 '18 at 09:02
  • Thanks for your help how to ask better question. I will read this article. If you understand my question now could you help me a little or and advice too. – Yılmaz edis Nov 01 '18 at 11:11

0 Answers0