两种访问thorugh I2C总线的方法有什么区别?

问题描述 投票:0回答:1

我看到了两种不同的方法来从I2C总线请求数据:

方法1:

  Wire.beginTransmission(MPU);
  Wire.write(0x43); // Gyro data first register address 0x43
  Wire.endTransmission(false);
  //https://www.arduino.cc/en/Reference/WireEndTransmission
  //false will send a restart, keeping the connection active. 

  Wire.requestFrom(MPU, 6, true); // Read 4 registers total, each axis value is stored in 2 registers
  GyroX = (Wire.read() << 8 | Wire.read()) / 131.0; // For a 250deg/s range we have to divide first the raw value by 131.0, according to the datasheet
  GyroY = (Wire.read() << 8 | Wire.read()) / 131.0;
  GyroZ = (Wire.read() << 8 | Wire.read()) / 131.0;

方法2:

Wire.beginTransmission(0b1101000); //I2C address of the MPU //Accelerometer and Temperature reading (check 3.register map) 
Wire.write(0x3B); //Starting register for Accel Readings
Wire.endTransmission();
Wire.requestFrom(0b1101000,8); //Request Accel Registers (3B - 42)
while(Wire.available() < 8);
accelX = Wire.read()<<8|Wire.read(); //Store first two bytes into accelX
accelY = Wire.read()<<8|Wire.read(); //Store middle two bytes into accelY
accelZ = Wire.read()<<8|Wire.read(); //Store last two bytes into accelZ
temp = Wire.read()<<8| Wire.read();

[第一种方法似乎没有终止传输,即Wire.endTransmission(false),而第二种方法未指定。它们之间有什么区别?哪个更好,即响应时间/循环时间。

也可以

0b1101000 and 0x3B

彼此相等?

c++ arduino i2c
1个回答
0
投票

一个是请求陀螺仪读数,其他是加速度计读数,它们是不同的东西。与您的其他问题相同,0b1101000是MPU的地址,而0x3B是加速度计寄存器地址(因此不相同)

© www.soinside.com 2019 - 2024. All rights reserved.