Библиотека TM4C123 I2C в Arduino Wire Library для MPU6050 - PullRequest
0 голосов
/ 30 октября 2018

Я учусь читать гироскопические данные MPU6050, но главная проблема в том, что я не смог достичь. Позвольте мне объяснить, почему эта проблема возникает.

Я нашел пример MPU6050 для Arduino MPU6050BasicExample .

Я начал менять базовый пример Arduino. Затем я применил все коды к своему проекту, кроме этих функций «writeByte», «readByte», «readBytes».

Я пытался изменить этот код в соответствии с Arduino следующим образом;

Это коды Arduino;

  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
}  

Это мои коды, которые я пытался изменить;

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
}

По моему мнению, если я перенесу коды Arduino в коды Tiva-c, я смогу прочитать гироскопические данные.

...