title: TM4C123 I2C Library to Arduino Wire Library for MPU6050
body: <p>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.</p>
  
  <p>I found MPU6050 example for Arduino <a href="https://github.com/kriswiner/MPU6050/blob/master/MPU6050BasicExample.ino" rel="nofollow noreferrer">MPU6050BasicExample</a>.</p>
  
  <p>I have started to change basic Arduino example. Then I applied all codes to my project except of these "writeByte", "readByte", "readBytes" functions.</p>
  
  <p>I have tried to change these code according to Arduino as follow;</p>
  
  <p>These are Arduino codes;</p>
  
  <pre><code>  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
  }  
  </code></pre>
  
  <p>These are my codes I have tried to change;</p>
  
  <pre><code>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
  }
  </code></pre>
  
  <p>In my opinion, if I port Arduino codes to Tiva-c codes, I will achieve to read gyro data.</p>